Reputation: 13545
$("#prevPage").live("click",function(e) {
.................
});
For example, when the user have already clicked on the prevPage
, the statement inside it is running, if the user click on it instantly , it will trigger again. However, I would like the click event trigger only after all the statement inside it have finish execution, How to achieve that?
Upvotes: 5
Views: 1593
Reputation: 10380
How about this or something similar:
<script type="text/javascript">
// disable command while function is being executed.
var sample = {
isExecuting : 0,
doWork : function (e) {
if (sample.isExecuting === 1) return;
sample.isExecuting = 1;
// do work -- whatever you please
sample.isExecuting = 0; // say: I'm done!
}
};
// live or bind
$("#prevPage").bind("click",function(e) {
sample.doWork(e);
});
</script>
simple 'shield' to block a multiple-call scenario.
Upvotes: 2
Reputation: 91
unbind() will do the work for you.
An alternate could be like using detach(). When your process is executing detach the button and when your process finsihes executing, use reattach() to get the button back. What I will suggest is use unbind().
Upvotes: 0
Reputation: 119827
Then set a flag on the element to check if it's clickable or not.
$("#prevPage").on("click",function(e) {
e.preventDefault();
//get the clickable attribute
//if it's not existent, its undefined hence "false"
var unclickable = this.unclickable;
//if it's not unclickable (it's clickable)
if(!unclickable){
//make the flag unclickable
this.unclickable = true;
//do stuff
//reset it back the way it was after operations
this.unclickable = false;
}
});
Upvotes: 1
Reputation: 1514
use the unbind function of jquery
$("#prevPage").unbind("click");
after your task finished
$("#prevPage").bind("click",function(){....your code here....});
Upvotes: 0
Reputation: 4144
Set a variable that your event triggered
var prevPageEventTriggered = false ;
and set it to ture
when event triggered
prevPageEventTriggered = true;
and then add condition for this in click event handler function
$("#prevPage").live("click",function(e) {
if ( prevPageEventTriggered ) {
return false;
}
// your code goes here
// ....
});
if it have finish execution, you can set it to false
. hope this will helps
Upvotes: 0