-
-
Save rambhairao/19dc3a406a9cdac9b5f5656804e893b1 to your computer and use it in GitHub Desktop.
event propagation in js
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
li{ | |
list-style-type: none; | |
display: inline-block; | |
} | |
div{ | |
width: 100px; | |
height: 100px; | |
} | |
#one{ | |
background-color: #b647b7; | |
} | |
#one2{ | |
background-color:#2c8e80; | |
} | |
#one3{ | |
background-color: #47a1b7; | |
} | |
#one4{ | |
background-color: #00ffa2; | |
} | |
#one7{ | |
background-color: #352a7c; | |
} | |
#one5{ | |
background-color: #ffde00; | |
} | |
#one6{ | |
background-color: #4ea8f3; | |
} | |
#one8{ | |
background-color: #a80dd0; | |
} | |
#one4{ | |
background-color: #00ffa2; | |
} | |
#one9{ | |
background-color: green; | |
} | |
#wrapper{ | |
width: 100% | |
} |
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"> | |
<meta name="viewport" content="width=device-width"> | |
<title>event propagation in js </title> | |
</head> | |
<body> | |
<div id="wrapper"> | |
<ul id="listner"> | |
<li> <div id="one" > </div> </li> | |
<li> <div id="one2"> </div> </li> | |
<li> <div id="one3"> </div> </li> | |
<li> <div id="one4"> </div> </li> | |
<li> <div id="one5"> </div> </li> | |
<li> <div id="one6"> </div> </li> | |
<li> <div id="one7"> </div> </li> | |
<li> <div id="one8"> </div> </li> | |
<li> <div id="one9"> </div> </li> | |
</ul> | |
</div> | |
</body> | |
</html> |
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
document.getElementById('listner').addEventListener('click', function(e){ | |
console.log(e.target.id); | |
console.log("on all"); | |
}, true); | |
document.getElementById('listner').addEventListener('click', function(e){ | |
console.log("click hs on listner"); | |
}, true); | |
document.getElementById('one3').addEventListener('click', function(e){ | |
console.log(e.target.id); | |
console.log("on 3"); | |
}, true); | |
document.getElementById('wrapper').addEventListener('click', function(e){ | |
console.log(e.target.id); | |
console.log("on wrapper"); | |
}, true); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment