why this code works here:
button.onclick = function() { block.classList.toggle('active'); if (this.innerHTML === 'скрыть') { this.innerHTML = 'подробнее'; } else { this.innerHTML = 'скрыть'; } }
but this is no longer:
function innerButton() { if (this.innerHTML === 'скрыть') { this.innerHTML = 'подробнее'; } else { this.innerHTML = 'скрыть'; } } button.onclick = function() { block.classList.toggle('active'); innerButton(); }
What am I doing wrong and how to make it work?
I have a lot of buttons on the page and I want to make a function to change the name of them separately
innerButton();
->innerButton.apply(this);
, as an option other than the one proposed in the answer. - Rostyslav Kuzmovych