K
K
KataGol2020-04-13 15:49:52
JavaScript
KataGol, 2020-04-13 15:49:52

How to show hidden block?

What needs to be added in this script so that after pressing the "Show text" button, the text that we have hidden appears again?

<div class="content-area">
            <h5 id="text">CONTENT AREA</h5>
            <button id="hideBtn">Скрыть текст</button>
 </div>

document.getElementById ('hideBtn').onclick = function() {
    document.getElementById ('text').hidden = true;   
    document.getElementById ('hideBtn').innerHTML = "Показать текст";
};

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Tigran Abrahamyan, 2020-04-13
@KataGol

<div class="content-area">
  <h5 id="text">CONTENT AREA</h5>
  <button id="hideBtn">Скрыть текст</button>
</div>

.hide-and-show {
  display: none;
}

const btn = document.getElementById('hideBtn');

btn.addEventListener('click', function() {
  document.getElementById('text').classList.toggle('hide-and-show');
  if (btn.innerHTML === 'Показать текст') {
    btn.innerHTML = 'Скрыть текст';
  } else {
    btn.innerHTML = 'Показать текст';
  }
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question