1

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!

Imesh Chandrasiri
  • 5,558
  • 15
  • 60
  • 103

2 Answers2

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
}); 

 

SEE HERE

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