That's not at all how it works? You have to bind and unbind to the same selector, and you have to rebind to a function again, just doing $('a').on('click')
does nothing.
For this you could use namespaced events
function fnDoVoteContent() {
var btnUpvote = ".btn-upvoting";
var btnDownVote = ".btn-downvoting";
// bind event handlers
$(document).on('click.custom', btnUpvote, function(){
vote(param1, param2, param3);
});
$(document).on('click.custom', btnDownVote, function(){
vote(param1, param2, param3);
});
}
function vote(param1, param2, param3) {
$.ajax({
url: votingUrl,
cache: false,
type: "POST",
dataType: "json",
beforeSend: function(){
//do business logic
// unbind has to be done on the same selector
$(document).off('click.custom');
},
complete: function(){
//do business logic
$(document).on('click.custom', btnUpvote, function(){
vote(param1, param2, param3);
});
$(document).on('click.custom', btnDownVote, function(){
vote(param1, param2, param3);
});
},
success: function(data) {
//update data
}
});
}