2
Guys I’m having a question.
I have a button:
<button type="button" class="btn btn-success btn-xs" onclick="vincularContato($(this))"><span class="glyphicon glyphicon-ok"></span></button>
And two functions, one linkContact and the other removeContact passing the button itself as parameter:
function removerContato(botao) {
var tempIdContato = botao.closest("tr")
.find(".idContato")
.text();
botao.removeClass('btn-danger');
botao.addClass('btn-success');
botao.html('<span class="glyphicon glyphicon-remove"></span>');
// botao.prop('onclick', null).off('click');
// botao.prop('onclick', vincularContato(botao)).off('click');
}
function vincularContato(botao) {
var tempIdContato = botao.closest("tr")
.find(".idContato")
.text();
botao.removeClass('btn-success');
botao.addClass('btn-danger');
botao.html('<span class="glyphicon glyphicon-remove"></span>');
// botao.prop('onclick', null).off('click');
// botao.prop('onclick', removerContato(botao)).off('click');
}
What I need is to change my button’s onclick function whenever it is clicked, switching from one function to another.
The button is changing span and class, but I can’t change onclick.
I commented on one of my tests, did some other ways but without success.
Could you help me?
or maybe he can create a variable and increase it and if the variable %2 returns 1 he does one thing or another.
– user83428
Good idea Pedro, tomorrow I will do just that, I hadn’t thought about it! Haha... Thanks
– Rafael Weber
It can be done yes @Viniciusputtimorais, however, you are saying yourself that you will have an "extra" job to do
criar uma variavel e ir incrementando ela
. Agrees?– Pedro Camara Junior
really, actually depends on the taste.
– user83428