Created
January 20, 2017 09:44
-
-
Save kuznetsovandrey76/39a1fba45c212c32415d000743211ab9 to your computer and use it in GitHub Desktop.
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
var div = document.querySelectorAll('div'), | |
result; | |
for (var i = 0; i < div.length; i++) { | |
result = div[i]; | |
result.addEventListener('click', function() { | |
alert(this.innerHTML); | |
}); | |
} |
Thank You. Useful Tip!
Thanks!
Thank you!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice, it's thanks you I got the answer. (2 years later ^^)
You can add another thing to your code now that there is EMACs 6 on JS:
Instead of doing the for
loop
, use theforEach
to select each 'div' element of the selectorAll, then apply the listener.