How can I simulate an anchor click via jquery?

prinzdezibel picture prinzdezibel · Apr 21, 2009 · Viewed 283.8k times · Source

I have a problem with faking an anchor click via jQuery: Why does my thickbox appear the first time I click on the input button, but not the second or third time?

Here is my code:

<input onclick="$('#thickboxId').click();" type="button" value="Click me" />

<a id="thickboxId" href="myScript.php" class="thickbox" title="">Link</a>

It does always work when I click directly on the link, but not if I try to activate the thickbox via the input button. This is in FF. For Chrome it seems to work every time. Any hints?

Answer

Stevanicus picture Stevanicus · May 12, 2012

What worked for me was:

$('a.mylink')[0].click()