Last active
August 7, 2018 11:50
-
-
Save geoffduke/fcacdbf0d8a5bde0be8f0c3f3c1a090d to your computer and use it in GitHub Desktop.
Typical Mouse event forloop
This file contains hidden or 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 lis = document.querySelectorAll("li"); | |
| for(var i = 0; i < lis.length; i++){ | |
| lis[i].addEventListener("mouseover", function () { | |
| this.style.color = "green"; | |
| }); | |
| lis[i].addEventListener("mouseout", function () { | |
| this.style.color = "black"; | |
| }); | |
| }; | |
| //Same Loop using classes. Style sheet added with the selected and done styles | |
| // var lis = document.querySelectorAll("li"); | |
| // for(var i = 0; i < lis.length; i++){ | |
| // lis[i].addEventListener("mouseover", function () { | |
| // this.classList.add("selected"); | |
| // }); | |
| // lis[i].addEventListener("mouseout", function () { | |
| // this.classList.remove ("selected"); | |
| // }); | |
| // lis[i].addEventListener("click", function () { | |
| // this.classList.toggle("done"); | |
| // }); | |
| // }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment