Last active
July 12, 2016 06:21
-
-
Save kikill95/ba4a8b0424e696924915a774b519a6b3 to your computer and use it in GitHub Desktop.
Example of work with DOM (events)
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.querySelector('body').innerHTML = '<div class="red"><div class="blue"><div class="green"></div></div></div><style>.red{background-color: red; width: 200px; height: 200px; padding-top: 50px; padding-left: 50px;} .blue{background-color: blue; width: 100px; height: 100px; padding-top: 50px; padding-left: 50px;} .green{background-color: green; width: 50px; height: 50px;}</style>'; | |
var red = document.querySelector('.red'), | |
blue = document.querySelector('.blue'), | |
green = document.querySelector('.green'); | |
red.addEventListener('click', function(event) { | |
console.log('red', event); | |
}); | |
blue.addEventListener('click', function(event) { | |
event.stopPropagation(); | |
console.log('blue', event); | |
}); | |
green.addEventListener('click', function(event) { | |
console.log('green', event); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment