I thought jQuery’s click() can let us add a handler or just click on an element?
However, I tried:
$(function() {
setTimeout(function() {
$('a').first().trigger('click'); // or click(), the same
}, 3000);
});
and waited 3 seconds and it won’t click on the first <a> element in the page… how come?
Update: this is related to What is the best way to make the Yahoo media player autostart, jQuery? and so there should already be event handler for clicking on a media, so how come .click(), which is the same as trigger('click'), not firing off that event handler?
Calling the
click()method does not simulate clicking the link. It calls anyclick()handlers on the affected element(s). That’s a subtle yet important difference. If you want to simulate clicking the link, there is no realiable cross-browser way of doing this.