javascript - 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 website. want show lightbox while click on h3
tag. have alert a
href(commented line) working fine. not working trigger. please see above code. , tell me why trigger('click')
not working in code.
thank you
edit - forgot lightbox. simple anchor link not working.
change javascript code this:
$(function(){ $('.parent-class h3').click(function(){ $(this).siblings('p').find('a')[0].click(); }); });
jquery trigger won't work because no click event binded element, javascript click function, simulate actual click 1 mouse!
Comments
Post a Comment