Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

106
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda