Skip to content

Instantly share code, notes, and snippets.

@jmlavoier
Created June 27, 2017 21:04
Show Gist options
  • Save jmlavoier/3ea5f4e5b7c997d58db202b0d2e065f2 to your computer and use it in GitHub Desktop.
Save jmlavoier/3ea5f4e5b7c997d58db202b0d2e065f2 to your computer and use it in GitHub Desktop.
const content = document.querySelector('.content')
const colors = ['red', 'blue', 'yellow', 'green', 'black'];
let index = 0;
// Sintaxe ES6
const eventDelegate = (tagName, callback) => event => {
if (event.target && event.target.tagName === tagName) {
return callback(event);
}
}
const changeColor = function (event) {
event.target.style.color = colors[index];
index = index < 4 ? index + 1 : 0;
}
content.onclick = eventDelegate('P', changeColor);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment