O
O
Oleg Sevoc2020-04-15 12:58:10
JavaScript
Oleg Sevoc, 2020-04-15 12:58:10

How to add text to change on click?

good afternoon, how to make that by clicking Read more .. the text changed to Hide?
<p class="hide_sub">Читать полностью..</p>

const readMore = document.getElementsByClassName('hide_sub')[0];

let click = 0;
readMore.addEventListener('click', () => {

    click++;
    if (click == 1) {
        document.getElementsByClassName('hide')[0].style.display = 'block';

    } else if (click == 2) {
        document.getElementsByClassName('hide')[0].style.display = 'none';


        click = 0;
    }
});<code lang="html">

</code>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Tigran Abrahamyan, 2020-04-15
@mrgreeg7

const readMore = document.getElementsByClassName("hide_sub")[0];

readMore.addEventListener("click", () => {
  if (readMore.textContent === "Читать полностью..") {
    readMore.textContent = "Скрыть";
  } else {
    readMore.textContent = "Читать полностью..";
  }
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question