Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question