Skip to content

Instantly share code, notes, and snippets.

@lmuzquiz
Last active March 13, 2017 00:50
Show Gist options
  • Save lmuzquiz/824946e19b58ff49edff3170f611d42c to your computer and use it in GitHub Desktop.
Save lmuzquiz/824946e19b58ff49edff3170f611d42c to your computer and use it in GitHub Desktop.
Utilizando el método getElementsByTagName
<script>
// Encontrar los elementos <li> y ponerlos en una variable
var elements = document.getElementsByTagName('li');
if (elements.length > 0) { // Si más de uno es encontrado
var el = elements[3]; // Selecciona el cuarto elemento de la colección
el.className = 'cool'; // Cambia el valor del atributo clase
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment