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

181
Visualizações
Hover on element within anchor tag without selecting anchor tag. JS or CSS

I am working on a Shopify theme where I need to select the product price & hover on it for tooltip. but the problem is those products all are within an anchor tag. I've tried to find a solution but there's not much info about it. Tried pointer-event: none; but this causes anchor not working anymore. I need the anchor tag to work & at the same time, I need the hover effect on price without selecting the anchor tag because that anchor tag is within a theme & selecting that will cause problems for different themes. SO I've made a Codepen simulation for it. check below & let me know if it is possible with CSS or js doesn't matter. Thank you.

I want to hover this box

enter image description here

a {
  font-family: sans-serif;
  text-decoration: none;
  color: black;
}

.card {
  width: 400px;
  margin: 20px auto;
  background: white;
  box-shadow: 0 0 5px 2px #999;
  border-radius: 4px;
  padding: 10px;
  text-align: center;
}

.card img {
  width: 100%;
  height: 220px;
  object-fit: cover;
}

.price-group {
  margin: 20px 0 5px;
  padding: 20px 0;
  background: #ddd;
}
<a href="">
  <div class="card">
    <img src="https://images.pexels.com/photos/90946/pexels-photo-90946.jpeg" alt="">
    <p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Excepturi, alias.
    </p>
    <div class="price-group">
      <span class="title">Sample Product</span>
      <span class="price">$100</span>
    </div>
  </div>
</a>

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

0

If I understand correctly, you are looking to be able to click the price without triggering the anchor, while not losing the functionality of the anchor.

This can be done with use stopPropagation and preventDefault

You can sort of 'mask' the hovering of anchor, by overwriting the hover actions of anchor.(bad UX though)

function check(event) {
  // prevent acheck or other functions of anchor 
  event.stopPropagation();
  // stops href redirection
  event.preventDefault();
  console.log('inner')
}

function acheck(event) {
  console.log('anchor')
}
a {
  font-family: sans-serif;
  text-decoration: none;
  color: black;
  
}

.card {
  width: 400px;
  margin: 20px auto;
  background: white;
  box-shadow: 0 0 5px 2px #999;
  border-radius: 4px;
  padding: 10px;
  text-align: center;
}

.card img {
  width: 100%;
  height: 220px;
  object-fit: cover;
}

.price-group {
  margin: 20px 0 5px;
  padding: 20px 0;
  background: #ddd;
}

.price-group:hover {
  background: red;
  cursor: pointer;
}

a:hover {
  cursor: default;
}
<a href="">
  <div class="card" onclick='acheck(event)'>
    <img src="https://images.pexels.com/photos/90946/pexels-photo-90946.jpeg" alt="">
    <p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Excepturi, alias.
    </p>
    <div class="price-group" onclick='check(event)'>
      <span class="title">Sample Product</span>
      <span class="price">$100</span>
    </div>
  </div>
</a>

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