onclick stop propagation code example

Example 1: onclick stoppropagation

<span onclick="event.stopPropagation(); alert('you clicked inside the header');">something inside the header</span>

Example 2: stop propagation event

$("span").click(function(event){
  event.stopPropagation();
  alert("The span element was clicked.");
});
$("p").click(function(event){
  alert("The p element was clicked.");
});
$("div").click(function(){
  alert("The div element was clicked.");
});

Example 3: html onclick stop propagation

// "event" is not universally supported, so instead grab the first
// argument passed through the onclick handler and call
// "stopPropagation()" on it
<div onclick="(arguments[0] ? arguments[0].stopPropagation() : false);">...</div>

Tags:

Misc Example