Skip to content

Instantly share code, notes, and snippets.

@jmlavoier
Last active June 28, 2017 13:37
Show Gist options
  • Save jmlavoier/36560836a0e19240c0b97d6424a08c9e to your computer and use it in GitHub Desktop.
Save jmlavoier/36560836a0e19240c0b97d6424a08c9e to your computer and use it in GitHub Desktop.
const allP = document.getElementsByTagName('p');
// Criando a função de callback
// Todos os eventos recebem como parâmetro o objeto event
// que permite pegarmos o elemento clicado event.target,
// e realizar outras funcionalidades.
const goToLastPosition = function (event) {
event.target.parentNode.appendChild(event.target);
}
// Percorro todos os elementos e aplico a função ao evento.
for (let i = 0; i <= allP.length; i++) {
allP[i].addEventListener('click', goToLastPosition);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment