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?
this approach works on firefox, chrome and IE. hope it helps someone:
To simulate a click on an anchor while landing on a page, I just used jQuery to animate the scrollTop property in
$(document).ready.
No need for a complex trigger, and that works on IE 6 and every other browser.I'd suggest to look at the Selenium API to see how they trigger a click on an element in a browser-compatible manner:
Look for the
BrowserBot.prototype.triggerMouseEvent
function.This doesn't work on android native browser to click "hidden input (file) element":
But this works:
Do you need to fake an anchor click? From the thickbox site:
If that is acceptable it should be as easy as putting the thickbox class on the input itself:
If not, I would recommend using Firebug and placing a breakpoint in the onclick method of the anchor element to see if it's only triggered on the first click.
Edit:
Okay, I had to try it for myself and for me pretty much exactly your code worked in both Chrome and Firefox:
The window pop ups no matter if I click the input or the anchor element. If the above code works for you, I suggest your error lies elsewhere and that you try to isolate the problem.
Another possibly is that we are using different versions of jquery/thickbox. I am using what I got from the thickbox page - jquery 1.3.2 and thickbox 3.1.
In Javascript you can do like this
and you can use it like