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 110 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
- 13,010
- 3
- 33
- 42

PSR
- 39,804
- 41
- 111
- 151
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,899
- 7
- 31
- 43

Arun P Johny
- 384,651
- 66
- 527
- 531