Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

115
Vistas
How do I connect this script to one of my buttons?

<button class="ordercolor" onclick="ordercolor()">Order Color</button> This is the button on HTML

var color = 
  ["#222f3e", "#dd260e", "#0ae196c", "#0ae127", "#0a7ce1", "#a60ae1", "#808000", "#00FF00", "#00FFFF", "#008080", "#FF5733"];
  var i = 0;
  addEventListener("click",
  function () {
  i = i < color.length ? ++i : 0;
  document.querySelector("body").style.background = color[i];

This is the script on Java.

That script applies on every button I got on HTML and I want it specific in one button. Can you help me apply it to the specific button ? Or maybe you have another script for changing colors in order on click, like green after red after blue (always the same) ?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need to name the function. If you are using onclick you do not need to use the event listener. Like this:

<button class="ordercolor" onclick="ordercolor()">Order Color</button>
<script>
var color = ["#222f3e", "#dd260e", "#0ae196c", "#0ae127", "#0a7ce1", "#a60ae1", "#808000", "#00FF00", "#00FFFF", "#008080", "#FF5733"];
var i = 0;
function ordercolor() {
i = i < color.length ? ++i : 0;
document.querySelector("body").style.background = color[i];
}
</script>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda