I wanna to disable the mouse clicking in some div.For this I have used the die function it is not working. Please let me know how can I do it? Is it possible in jquery?
2 Answers
This is very simple. Use this code:
$("#DIV_ID").click(function(e){
e.preventDefault();
e.stopPropagation()
});
3 Comments
Explosion Pills
There probably is no default action performed by the div .. you may want to use
stopImmediatePropagation instead or even unbind whatever event is bound to it.Arvind Bhardwaj
@ExplosionPills I am not sure about
stopImmediatePropagation. Can you explain difference b/w stopImmediatePropagation and stopPropagation?Explosion Pills
It prevents the calling of other events bound to the same element.
stopPropagation only stops the calling of events bound to ancestors.use stopImmediatePropagation()...
Keeps the rest of the handlers from being executed and prevents the event from bubbling up the DOM tree.
try this
$("#yourDivId").click(function(e){
e.preventDefault();
e.stopImmediatePropagation();
});