There are several events bound to each elements. some times, a parent and a child element both contain click events! There for if I click on the child element, the parent element gets fired too. How can I prevent these events from getting fired using jquery!
Asked
Active
Viewed 85 times
1
-
5Aloha docs! http://api.jquery.com/event.stopPropagation/ – elclanrs Jun 05 '13 at 04:12
-
1See this answer on stackoverflow http://stackoverflow.com/a/2364639/2454105 – fuentesbusco Jun 05 '13 at 04:17
2 Answers
7
You can use event.stopPropagation()
Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event.
$("p").click(function(event){
event.stopPropagation();
// do something
});
Asif Mushtaq
- 12,720
- 3
- 32
- 42
PSR
- 38,073
- 36
- 106
- 149
2
You can use
event.stopImmediatePropagation():- If you want to prevent other event handler registered in the element from firing too
or
event.stopPropagation():- If you want to prevent only the handlers registered in the parent element
Dineshkani
- 2,715
- 7
- 29
- 43
Arun P Johny
- 376,738
- 64
- 519
- 520