Created
August 23, 2014 18:45
-
-
Save dodalovic/2806358cb74d25659cda to your computer and use it in GitHub Desktop.
Prevent event bubbling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
var eventDetails = function(element, event) { | |
event.stopPropagation ? event.stopPropagation() : (event.cancelBubble = true); | |
console.log("target.id:" + event.target.id + ", this.id:" + element.id); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Insert title here</title> | |
<script type="text/javascript" src="bubbling/js/bubbling.js"></script> | |
</head> | |
<body> | |
<div id="1" onclick="eventDetails(this, event);"> | |
<p id="d1-p">some 1 content</p> | |
<div id="2" onclick="eventDetails(this, event);"> | |
<p id="d2-p">some 2 content</p> | |
<div id="3" onclick="eventDetails(this, event);"> | |
<p id="d3-p">some 3 content</p> | |
</div> | |
</div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment