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

365
Vistas
JQuery trigger() not working

  $(function(){
      $('.parent-class h3').click(function(){
         $(this).siblings('p').find('a').trigger( "click" );
         //var h = $(this).siblings('p').find('a').attr( "href" );
         //alert(h);
      });
  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

<div class="parent-class">
    <p class="child-class">
        <a href="hello.jpg" data-rel="lightbox-1">Lightbox Image</a>
    </p>
    <h3>Title Here</h3>
</div>

I have used lightbox in my website. I want to show lightbox while click on h3 tag. I have alert a href(commented line) this is working fine. But not working trigger. Please see above my code. and tell me why trigger('click') not working in my code.

Thank you

Edit - Forgot about lightbox. simple anchor link not working.

about 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

Change your javascript code to this:

$(function(){
      $('.parent-class h3').click(function(){
         $(this).siblings('p').find('a')[0].click();
      });
});

jQuery trigger won't work because no click event is binded to element, this is a javascript click function, which simulate the actual click like one with mouse!

about 4 years ago · Santiago Trujillo Denunciar

0

You can use direct click function.

  $(function(){
      $('.parent-class h3').click(function(){
         $(this).siblings('p').find('a').click()
         //var h = $(this).siblings('p').find('a').attr( "href" );
         //alert(h);
      });
  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

<div class="parent-class">
    <p class="child-class">
        <a href="hello.jpg" data-rel="lightbox-1">Lightbox Image</a>
    </p>
    <h3>Title Here</h3>
</div>

about 4 years ago · Santiago Trujillo Denunciar

0

 $(function(){
      $('.parent-class h3').click(function(){
         //$(this).siblings('p').find('a').trigger( "click" );
         var h = $(this).siblings('p').find('a').attr( "href" );
         location.href = h;
      });
  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class="parent-class">
    <p class="child-class">
        <a href="hello.jpg" data-rel="lightbox-1">Lightbox Image</a>
    </p>
    <h3>Title Here</h3>
</div>

about 4 years ago · Santiago Trujillo 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