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

http://api.jquery.com/trigger/


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -