top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

What is the difference between event.stopPropagation() and event.preventDefault() in jQuery?

0 votes
636 views
What is the difference between event.stopPropagation() and event.preventDefault() in jQuery?
posted Sep 10, 2014 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

event.stopPropagation()
stopPropagation stops the event from bubbling up the event chain or we can say it prevents the default action of the event from triggering. One thing to remember is that it does not stop the event propagation to parent DOM elements.
Ex
With stopPropagation only the buttons click handler is called and the divs click handler never fires.

event.preventDefault()
preventDefault prevents the default action the browser makes on that event or we can say that it orevents the default action of the event from propagating to parent DOM elements which stopPropagation does not.
Ex
In preventDefault only the browsers default action is stopped but the div's click handler still fires.

answer Sep 10, 2014 by Nikhil Pandey
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...