Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

172
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda