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

367
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 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