Created
June 27, 2017 21:03
-
-
Save jmlavoier/1d836dcd73234f2c4a9c219f38763235 to your computer and use it in GitHub Desktop.
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
const p = document.querySelector('.p1'); | |
const colors = ['red', 'blue', 'yellow', 'green', 'black']; | |
let index = 0; | |
const changeColor = function (event) { | |
event.target.style.color = colors[index]; | |
index = index < 4 ? index + 1 : 0; | |
} | |
// Diretamente do método do elemento | |
p.onclick = changeColor; | |
// ou aplicando o evento | |
p.addEventListener('click', changeColor); | |
// ou para remover o evento | |
p.removeEventListener('click', changeColor); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment