event.stopPropagation() Method

event.stopPropagation() method use when any parent element on event affect that child element at that time using event.stopPropagation() method to stop parent element event.

In below example when click on second div it’s alert both first and second div. Now when click on p element alert “p element was clicked” but that time his parent first and second div not alert becouse of event.stopPropagation().

TRY IT NOW

event.preventDefault() Method

event.preventDefault() function use for the prevent link, submit button to submit data.

TRY IT NOW

event.stopImmediatePropagation() Method

event.stopImmediatePropagation() method use when any element have two and more then two event run at that time to stop other event for stopImmediatePropagation() method use.

In below example only first alert executed, second and third alert not executed because first alert have event.stopImmediatePropagation().

TRY IT NOW