Reputation: 2733
so i have a jquery function that does something on the click of an anchor tag.now i want to make the button unresponsive to jquery on subsequent clicks. what should i do? what i am doing is changing the innerHTML of the anchor tag on the first click and doing an AJAX call and during this time period i want nothing to happen when the user click on the same anchor tag again.
This is how i handle clicks through jquery
$('.profileEdit label a').live('click', function () {
// do something
});
Upvotes: 0
Views: 392
Reputation: 247
If i understood what you want you can just remove the 'onclick' attribute before the ajax call and set it up again at the end (success or fail).
@EDIT: final solution codes
function update(){
$("#bb").html('Updating');
$("body").off('click',"#bb");
$.ajax({
type: "POST",
url:"profileUpdate.asmx/HelloWorld",
data: "{ 'value': '" + document.getElementById(string).value + "'" + ",'column':'" + string + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
defaultSetter();
},
error: function (msg) {
defaultSetter();
}
});
}
function defaultSetter(){
$("#bb").html("Test");
$("body").on('click','#bb', update);
}
$(document).ready(function(){
defaultSetter();
});
jsfiddle: http://jsfiddle.net/V3AAF/
Upvotes: 2
Reputation: 68586
Could you not just use one() if you only want the action to happen once on the first click?
$('.profileEdit label a').one('click', function () {
alert('This will only alert on the first click');
});
If you happened a handler for further clicks on that element, just use return false, to prevent anything from happening after the first click:
$('a').on('click', function () {
return false;
alert('first time!');
});
Upvotes: 1