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

103
Vistas
Want to hold for loop array in an event listener so I can send it as a parameter for a function

I'm trying to change the background image depending on which symbol is being hovered but when I try to return changebackground([i])it always returns an array with length 1 and the number 0.

How can I make it so it returns the number of the symbol that was hovered? for example, If the second symbol is hovered, I want it to return a checkbackground([1]) to the function changebackground(logo) Here you can look at the symbols to get an idea.

Below is my code

let background = document.getElementById("main_home_container");
let factionlogo = document.getElementsByClassName("home_image");


for (i = 0; i < factionlogo.length; i++) {
  factionlogo[i].addEventListener("mouseenter", function() {
    changebackground([i])
  });
  factionlogo[i].addEventListener("mouseleave", revertbackground);
}

function changebackground(logo) {
  if(logo == 0) {
    background.style.backgroundImage = 'url("/Img/bg1.png")';
  } else if(logo == 1) {
    background.style.backgroundImage = 'url("/Img/bg2.png")';
  }
  };

function revertbackground() {
  background.style.backgroundImage = 'url("/Img/home.png")';
  };
about 4 years ago · Juan Pablo Isaza
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