1
    <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 a big image). What i do wrong?

----Edited---- Thank you guys, but .trigger() is not working too. I resolved this problem something like this:

$(document).ready(function() {
            $('div.imgtumb img').click(function() {
            window.location.href = $('a.imgtarget').attr("href");
            });
        });

----Edited 2--- Question which explained why .click() is not working with a tag

Community
  • 1
  • 1
GrigorTaff
  • 11
  • 4

3 Answers3

1

try this:

<script>
    $(document).ready(function() {
        $('div.imgtumb img').click(function() {
        $('a.imgtarget').trigger('click');
        });
    });
</script>

the event trigger is the event to make another event to an element

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

Alessandro Minoccheri
  • 35,521
  • 22
  • 122
  • 171
0

use trigger()

. A call to .trigger() executes the handlers in the same order they would be if the event were triggered naturally by the user:

try this

$('a.imgtarget').trigger('click');

instead of

 $('a.imgtarget').click();
bipen
  • 36,319
  • 9
  • 49
  • 62
0

try to use this instead of .click()

window.open(
  'toBigImg',
  '_blank'
);