<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/themes/ui-lightness/jquery-ui.css">
<div class = "test">
Parent Div 1
<p href="#">stopPropagation Test</p>
</div>
<hr>
<div class = "test1">
Parent Div 1
<span class="immediate" href="#">stopImmediatePropagation Test</span>
</div>
CSS
span {
display: block;
}
JavaScript
$(".test").click(function(event){
//Attaching the event to the parent or outer element
$(this).css("background-color", "cyan");
});
$("p").click(function(event){
//This function only remove the handler of the parent element not current or itself
event.stopPropagation();
$(this).css("text-decoration", "underline");
});
$("p").click(function(event){
$(this).css("background-color", "red");
});
$("p").click(function(event){
$(this).css("font-size", "50px");
});
//Here Example for the event.stopImmediatePropagation();
$(".test1").click(function(event){
//Attaching the event to the parent or outer element
$(this).css("background-color", "bisque");
});
$(".immediate").click(function(event){
//This function removes all the handler of the parent element or the current element as well itself
event.stopImmediatePropagation();
$(this).css("text-decoration", "underline");
});
$(".immediate").click(function(event){
$(this).css("background-color", "red");
});
$(".immediate").click(function(event){
$(this).css("font-size", "50px");
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.