Skip to content

tiger986/preventBubbles

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

Compatible writing to prevent bubbles

HTML code

<div class="d1">
		d1
    <div class="d2">
        d2
       <div class="d3">
           d3
       </div>
    </div>
</div>

JS code

$(".d1").click(function () {
    alert("d1");
});
		
$(".d2").click(function () {
    preventBubble(); //Prevent bubble event call (written in an event)
    alert("d2");
});
		
$(".d3").click(function () {
    preventBubble(); //Prevent bubble event call (written in an event)
    alert("d3");
});
		
//Prevent bubble events (written in JS) (compatible with IE, Firefox, and Google)
function preventBubble (event) {  
    var e=arguments.callee.caller.arguments[0]||event; 
    if (e && e.stopPropagation) {  
	e.stopPropagation();  
    } else if (window.event) {  
	window.event.cancelBubble = true;  
    }  
}

About

Compatible writing to prevent bubbles

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages