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

141
Visualizações
How to target an id inside of a div class when I hover a different parent div class with jquery?

So as the question says, I am trying to hover the class button1 and get the id of 'css'. With my current code, all I get is the id html. I need to get a unique id that's pertinent to which button I hover. I'm still newer to jquery and javascript in general but I can't seem to find any information on this topic so any reference source would be great too if possible.

Here's my code:

HTML

<div class="button1">       
     <div class="text">
          <p>Skill<br /> <span class="Score" id = "html">10/10 </span> </p>
     </div>

     <div class="button1 Overlay">
     </div>
<div class="button1">       
     <div class="text">
          <p>Skill<br /> <span class="Score" id = "css">9/10 </span> </p>
     </div>

     <div class="button1 Overlay">
     </div>
</div> 

Jquery

('.button1').mouseover(function(event) {
    $(".text").attr('id');
})
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

With your current code you get nothing, since .text does not have ID and result is never used. Use $(this).find('.Score').attr('id')[1].

Note few bug fixes:

  1. ('.button1').mouseover is missing $
  2. You have nested .button1 (first one is not properly closed, use proper indentation for easier debugging), so it's impossible to find singe element, because you hover on top most element

$('.button1').mouseover(function(event) {
  console.log($(this).find('.Score').attr('id'))
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="button1">
  <div class="text">
    <p>Skill<br /> <span class="Score" id="html">10/10 </span> </p>
  </div>

  <div class="button1 Overlay">
  </div>
</div>
<div class="button1">
  <div class="text">
    <p>Skill<br /> <span class="Score" id="css">9/10 </span> </p>
  </div>

  <div class="button1 Overlay">
  </div>
</div>

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