Easy, stopPropagation
stops any events bubbling up to its container, container container, etc. etc.
Here is a live example: http://jsfiddle.net/5B7sw/
HTML:
<div id="container"> <button id="propagate">Propagate</button> <button id="nopropagate">Do not Propagate</button> </div>
and js:
$('#container').click(function(){ console.log('container click') ; }); $('#propagate').click(function(){ console.log('propagateclick'); }); $('#nopropagate').click(function(e){ console.log('nopropagateclick'); e.stopPropagation(); });
Pressing the Distribution button (default behavior) will record the spread of the click and hold back to the console. Pressing a button that includes an e.stopPropagation()
call will not print a โclick click containerโ message because propagation to the container has been stopped.
source share