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,428
  • 13
  • 56
  • 101

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
  • 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