A
A
aviatoru2020-04-25 11:50:03
JavaScript
aviatoru, 2020-04-25 11:50:03

How to change button text on click?

How can I make the button change its name on each click? Thanks

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2020-04-25
@aviatoru

btn.textContent = btn.classList.contains('show')
    ? 'Скрыть'
    : 'Показать';

A
anikavoi, 2020-04-25
@anikavoi

<button id="btn" type="button" onclick="btnToggle(this);">
....
function btnToggle(obj){
   obj.innerText="new text";
};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question