Skip to content

Instantly share code, notes, and snippets.

@carlosmendozaweb
Created May 16, 2019 20:54
Show Gist options
  • Save carlosmendozaweb/8602edc72bbd404cc36462f1fb7c3f49 to your computer and use it in GitHub Desktop.
Save carlosmendozaweb/8602edc72bbd404cc36462f1fb7c3f49 to your computer and use it in GitHub Desktop.
Ejemplo de cómo recorrer array en Javascript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<button class="Btn" onclick="CambiarColores();">Btn 1</button>
<button class="Btn" onclick="CambiarColores();">Btn 2</button>
<button class="Btn" onclick="CambiarColores();">Btn 2</button>
<style>
.Btn{
padding: 6px;
}
.Btn-Verde{
background: green;
}
</style>
<script>
function CambiarColores() {
var Elementos = document.getElementsByClassName('Btn');
for (var i = 0; i < Elementos.length; i++){
Elementos[i].className = 'Btn Btn-Verde';
}
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment