Reputation: 18790
I have a left tree. Its structure is like this
MainCategory Category1 Subcategory1 Subcategory2 Category2 Subcategory3 Subcategory4 Subcategory5 Category3 . .. etc like that
If user click any of the MainCategory/Category/Subcategory I need to disable/prevent repeated/multiple click on same link until the result come. How can I do that using jquery?
Upvotes: 3
Views: 2736
Reputation: 52809
May be just use a class to check if its already clicked.
If clicked, do not execute, and remove the class on success and failure.
Prototype -
$('.selector').click(function(){
if(!$(this).hasClass('someclass')){
$(this).addClass('someclass');
$.ajax({
url: "test.html",
success: function(){
$(this).removeClass("someclass");
},
error: function(){
$(this).removeClass("someclass");
}
});
}
})
Upvotes: 1
Reputation: 10315
if you use jQuery 1.7 you can use the off() and on() functionality
example:
var foo = function () {
// code to handle some kind of event
};
// ... now foo will be called when paragraphs are clicked ...
$("body").on("click", "p", foo);
// ... foo will no longer be called.
$("body").off("click", "p", foo);
if you use an older version you could unbind() and bind() the event
example:
var foo = function () {
// code to handle some kind of event
};
// ... now foo will be called when paragraphs are clicked ...
$("body p").bind("click", foo);
// ... foo will no longer be called.
$("body p").unbind("click");
Upvotes: 2