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

126
Vistas
Prevent click event for wrapper when inner link is click

Here is the example for UI element construct,

HTML

  <div class='wrap'>
          <a class='inner-link' href="#">Link</a>
    </div>

CSS

.wrap
{
  background:#CDD4E0;
  width:300px;
  height:100px;
  padding:20px;
}

.wrap:hover
{
  background:#868B93;
}

jQuery

   $('.wrap').click(function () {
             alert("Handler for wrap container click.");
         });
         
   $('.inner-link').click(function () {
             alert("Handler for inner link click");
         });

What I want to do is to prevent the container with the class .wrap click event when I click the link inside.
You can reference this fiddle example.
Current code fire $('.wrap').click when I do for $('.inner-link').click.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Add if to check if the target does not contain class inner-link.

UPDATE: Oh, the comment has a better way to solve it.

$(".wrap").click(function (e) {
  if (e.target.className !== "inner-link") { // add this
    alert("Handler for wrap container click.");
  }
});

$(".inner-link").click(function (e) {
  e.stopPropagation(); // or add this
  alert("Handler for inner link click");
});
about 4 years ago · Juan Pablo Isaza Denunciar

0

Try to use event.stopPropagation

Your jQuery codes should be modified as below:

$('.wrap').click(function () {
  alert("Handler for wrap container click.");
});

$('.inner-link').click(function (event) {
  event.stopPropogation();
  alert("Handler for inner link click");
});
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