G
G
goodfornothing2017-08-01 12:02:38
Angular
goodfornothing, 2017-08-01 12:02:38

How can I change the name of a button when it is clicked?

Hello everyone. There is a button, how to make it so that when you click on the button, its name changes? For example: it was "Edit", clicked, it became "Save". Thanks in advance for your answer.

<button pButton type="button" label="Редактировать" style="width:auto"></button>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
AlexanZem, 2017-08-12
@AlexanZem

<button #button (click)="changeButton(button)">Редактировать</button>

changeButton(button) {
    button.innerText = "Сохранить";
  }

T
twobomb, 2017-08-01
@twobomb

For all buttons.

document.querySelectorAll("button").forEach(function(el){
  	el.addEventListener("click",function(){
      if(!this.dataset.secondname)
        return;
       var tmp = this.innerHTML;
       this.innerHTML = this.dataset.secondname;
       this.dataset.secondname = tmp;
    },false)
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question