I have a div
that is returned from an ajax call which contains an a
. I need to click it in javascript, however I cannot find a way that works in both IE6 and FF.
This works in FF but generates an object required error in IE6:
$('#mylink').click();
This works in IE6 but generates a $("#mylink").get(0).click is not a function error in FF.
$('#mylink').get(0).click();
Any ideas on why this is and what kind of solution is available?
EDIT:
Using trigger returns the same error as click in IE6:
$('#mylink').trigger('click');
EDIT:
Placing the code in a timer does not change the behavior:
setTimeout(function() {
$('#mylink').click();
}, 100);
EDIT:
As a workaround, this functions. But it would be nice to better understand the issue. This is not a jQuery issue alone (or maybe at all). The IE6 JavaScript error comes out of MicrosoftAjax.js so it has something to do with that.
var anchor = $('#mylink');
if (anchor.get(0).click) {
anchor.get(0).click();
}
else {
anchor.click();
}