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

161
Visualizações
How to first trigger ul hover AND THEN li hover event with jQuery?

I have a <ul id="list"> and <li class="item-class">. When user hovers over an <li> inside of <ul> I want to first trigger the <ul> hover and then <li> hover because in my particular situation the order is significant. However, jQuery first fires <li> hover and then the <ul> event - is there a way to revert this order?

Let's have an unordered list:

  <ul id="list">
    <li class="list-item"> Argentina </li>
    <li class="list-item"> Mexico </li>
    <li class="list-item"> Brazil </li>
  </ul>

and this jQuery code:

function bindHoverEvents() {
    $('#list').hover(() => console.log("1. List hover"),
                     () => console.log("4. List unhover"));
    $('.list-item').hover(() => console.log("2. Item hover"),
                          () => console.log("3. Item unhover."));
}

When user hovers over an <li> and then unhovers back I a want to see

"1. List hover"
"2. Item hover"
"3. Item unhover."
"4. List unhover"

in the console, however, for some reason I see this:

"2. Item hover"
"1. List hover"
"3. Item unhover."
"4. List unhover"

Here's MRE: http://jsfiddle.net/frz24w9L/

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