davidino
davidino

Reputation: 231

jQuery dispatch event? How to

how can i dispatch an event on my window ready? For example in my code i've got:

$("#info").click(function(){
// do stuff
});

I need to call this function the first time without have a click on #info, in the way // do stuff.

Upvotes: 7

Views: 35663

Answers (2)

Skilldrick
Skilldrick

Reputation: 70859

A better way might be to make a function that does the required stuff, then do $(document).ready(myFunc); and $("#info").click(myFunc);.

Upvotes: 11

Darin Dimitrov
Darin Dimitrov

Reputation: 1038930

You could use the .trigger() method:

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

or simply:

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

which would be the same.

Upvotes: 13

Related Questions