I am trying to prevent multiple clicks on links and items, which is causing problems.
I am using jQuery to bind click events to buttons (jQuery UI) and image links (<a><img /></a>).
Is there a way to do-once-for-all prevent other events from firing after a click occurs?
Or do I have to maintain a global variable called _isProcessing and set it to true for each event handler?
Thanks
Edit: (clarification)
Thanks for your answers, my problem isn’t preventing the bubbling of the event, but preventing multiple concurrent clicks.
There are various ways to prevent concurrent clicks from running the code.
One way is to
unbind('click')on the element, then.bind()it again when you’re ready.I’d rather use some sort of flag. It could be a variable, but I’d rather assign a class to the element, like
.processing, and remove it when done. So you would have the handler check for the existence of that class to determine of the code should run.Another option is to use the elements
.data()to set a similar flag, like$(this).data('processing', true);Then set it to false when done.