javascript - How to activate <a> event by clicking on another element -
<div class="imgtumb"><img src="..."></div> <a href="tobigimg" class="imgtarget">sometext</a> <script> $(document).ready(function() { $('div.imgtumb img').click(function() { $('a.imgtarget').click(); }); }); </script>
the link not work (dont open big image). wrong?
----edited---- thank guys, .trigger() not working too. resolved problem this:
$(document).ready(function() { $('div.imgtumb img').click(function() { window.location.href = $('a.imgtarget').attr("href"); }); });
----edited 2--- question explained why .click() not working tag
try this:
<script> $(document).ready(function() { $('div.imgtumb img').click(function() { $('a.imgtarget').trigger('click'); }); }); </script>
the event trigger event make event element
Comments
Post a Comment