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

103
Visualizações
Hover and selectors

I am completely new to Javascript / Jquery and I have a problem.

Suppose in my html page I have a number (undefined) of class to hover (when I hover something happens). Here I put 2 examples.

<div class='hover' id='hov33749'>Wikipedia</div>
<div class='hover' id='hov32747'>Google</div>

How to :

  1. Apply a function when I hover on Google or Wikipedia
  2. Retrieve the div corresponding to the hover (id, text, position on the page etc.)

I tried to put a random id and put some regex but it doesn't work well

I thank you in advance

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Since you are starting out with JavaScript, I'd suggest refrain JQuery for now and understand how the language itself works.

The following code adds an eventListener to all elements with class hover, the functionality of which is in onHover method

const onHover = (e) => {
    const id = e.target.id;
  const text = e.target.textContent;
    console.log(id, text);
}

const hover = document.querySelectorAll(".hover");
hover.forEach(item => item.addEventListener("mouseover", onHover));
<div class='hover' id='hov33749'>Wikipedia</div>
<div class='hover' id='hov32747'>Google</div>

about 4 years ago · Juan Pablo Isaza Relatório

0

See JQuery documentation .hover()

$(".hover").each(function(){
    $(this).hover(function(){
        // Do something ...
        console.log("Text: " + $(this).text() + ", Id: " + $(this).attr("id"));
    });
});
about 4 years ago · Juan Pablo Isaza Relatório
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