Pages

Thursday, June 15, 2017

Event.stopPropagation() and Event.preventDefault()



1. event.stopPropagation() stops an event from bubbling up the event chain

2. event.preventDefault() will only prevent browser’s default action on that event from occurring, but the event still propogates up the event chain.


Example

$("#myDiv").click(function() {
   alert('click on #myDiv');
});

$("#divButton").click(function(e) {
   alert('button click');
   e.stopPropagation();
});

No comments:

Google
 

Java-Struts