Personal I have 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 another 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 the onclick function of my button whenever it is clicked, switching from one function to another.
The button is changing the span and class, but I can not change the onclick.
I commented one of my tests, I did some other ways but without success.
Could you help me?