A
A
AND2021-06-16 12:17:34
css
AND, 2021-06-16 12:17:34

How to hide a div block permanently?

Hey! I have a simple authorization form (Password, Name) when all fields are filled in, and when I click on the buttons, the div block is hidden.
So, but when the page is updated, it is shown again, how can I hide it forever after the first authorization?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey delphinpro, 2021-06-16
@daniziat

<div id="hide_forever">
  Div, который прячется навсегда
</div>
<button id="button1">Скрыть DIV</button>
<script>
  const div = document.getElementById('hide_forever');
  const button = document.getElementById('button1');
  const status = localStorage.getItem('div_hidden');
  if (status) {
    div.style.display = 'none';
  }
  button.addEventListener('click', () => {
    localStorage.setItem('div_hidden', '1');
    div.style.display = 'none';
  });
</script>

M
Mesuti, 2021-06-16
@Mesuti

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question