I have some code which is using delegate method of jquery.
e.g.:
$(document).delegate('.forImg','dblclick',function(event){.
.
.
.
}
I have multiple elements with the same class but different ids (unique). My application requires me to stop an event for some element. If I use the same syntax as the delegate for undelegate it removes the event for all the elements with that class. e.g
$(document).undelegate('.forImg','dblclick');
But I actually want to remove the event only for a particular element with a particular id. I have tried many combinations wherein I am giving the selector as that id. But no effect the elements still continue to respond to the event.
I have read that a single handler is created for the document where the selector is checked. I guess thats why even if i ask it to undelegate the handler continues to execute.
How should I do this without having to give delegate for each element?
That is why the classes are given. But I need control on each elements events.
Any help/ suggestions are welcome.
Thanks
Alrighty, I thought of something after all…
So, you’ve delegated a listener. On double-click of any of the selected elements, a function will execute, right?
But if you bind ANOTHER double-click listener over top of it, and stop propagation, it will no longer bubble up:
Fiddle: http://jsfiddle.net/p5e2e/7/
Note: I’m using ‘bind’ because the OP seems to be using older syntax for whatever reason (not everyone is using jQuery 1.7+), but if the latest jQuery is used, swap
onin place ofbind.