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

302
Visualizações
How to remove icons from outer div on inner div hover?

There are two divs, both divs have an icon in the corner to edit their properties. I want only one icon to be present at any particular time. When hovering over outer div, the icons are shown in the outer div corner. When hovering on inner div the icon box is shown in both the divs. How can I suppress the outer divs icon box when hovering over inner div. Here is my code

$(".icons").parent().hover(function() { // Mouse over
  $(this).find('.icons').first().css('display', 'block');
}, function() { // Mouse out
    $(this).find('.icons').first().css('display', 'none');
});
    .outer{
        width: 500px;
        height: 200px;
        background-color: fuchsia;
        display: flex;
        align-items: center;
        justify-content: center;
        position: relative;
    }
    .inner{
        width: 300px;
        height: 100px;
        background-color: #2c132c;
        position: relative;
    }
    .icons{
        content: '^';
        size: 22px;
        background-color: gold;
        color: honeydew;
        width: 20px;
        height: 15px;
        position: absolute;
        top: 0;
        left: 0;
        display: none;
    }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<div class="outer">    
    <div class="icons"></div>
    <div class="inner">
        <div class="icons"></div>
    </div>
</div>

I want to show only one icons box at a time. So when inside inner div, I don't want to show the icons from outer div.

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

0

I made it more flexible with mouseenter and mouseleave by making it active when you enter the Div and when you leave the Div his parent will be active

 $(".show-icons").mouseenter(function (e) { // Mouse over
    $(".icons").hide();
    $(this).find('.icons').first().show();
  });
  $(".show-icons").mouseleave(function (e) { // Mouse over
    $(".icons").hide();
    $(this).parents(".show-icons").first().find('.icons').first().show()
  });
.outer {
    width: 500px;
    height: 200px;
    background-color: fuchsia;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
  }

  .inner {
    width: 300px;
    height: 100px;
    background-color: #2c132c;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .inner-2 {
    width: 100px;
    height: 50px;
    background-color: #ccc;
    position: relative;
  }

  .icons {
    content: '^';
    size: 22px;
    background-color: gold;
    color: honeydew;
    width: 20px;
    height: 15px;
    position: absolute;
    top: 0;
    left: 0;
    display: none;
  }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

  <div class="outer show-icons">
    <div class="icons"></div>
    <div class="inner show-icons">
      <div class="icons"></div>
      <div class="inner-2 show-icons">
        <div class="icons"></div>
      </div>
    </div>
  </div>

about 4 years ago · Juan Pablo Isaza Relatório

0

The only way I can think of implementing this would be to keep a separate check in JS, if the mouse hovers over the inner div then just make the outer div icons display: none, however, I am not so sure how this will be implemented as I don't use jquery so far and also haven't looked into the hover() function.

You can make it like, if the mouse hovers over the outer div, then display its outer icons, and in case it goes and also hover over the inner div, then you can set the outer icons display to none and inner ones to display block. You might need event listener for this I believe.

about 4 years ago · Juan Pablo Isaza Relatório

0

Because the inner div is completely contained within the outer div you could just listen for the mouse movements (over/out) on the outer div, pick up what the target element is and set/unset its icons to display block/none.

  const outer = document.querySelector('.outer');
  outer.addEventListener('mouseover', function (e) {
    e.target.querySelector('.icons').style.display = 'block';
  });
  outer.addEventListener('mouseout', function (e) {
    e.target.querySelector('.icons').style.display = 'none';
  });
        .outer{
            width: 500px;
            height: 200px;
            background-color: fuchsia;
            display: flex;
            align-items: center;
            justify-content: center;
            position: relative;
        }
        .inner{
            width: 300px;
            height: 100px;
            background-color: #2c132c;
            position: relative;
        }
        .icons{
            content: '^';
            size: 22px;
            background-color: gold;
            color: honeydew;
            width: 20px;
            height: 15px;
            position: absolute;
            top: 0;
            left: 0;
            display: none;
        }
    <div class="outer">    
        <div class="icons"></div>
        <div class="inner">
            <div class="icons"></div>
        </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