Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulate a click with jQuery?

After 5 seconds, I need to simulate a click on a button.

var count = 5;
countdown = setInterval(function () {
    $("#count").html(count);
    if (count == 0) {
        alert("Jotain pitäis tapahtua. kai");
        //What should I put instead of this line?
    }
    count--;
}, 1000);
return false;

Is it even possible?


1 Answers

$('#my_button').trigger('click');

That ought to do it for you.

Or as others have posted the shorthand:

$('#my_button').click();