Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 212
davidino Avatar asked Nov 29 '10 22:11

davidino


People also ask

How do you trigger a click event?

The HTMLElement.click() method simulates a mouse click on an element. When click() is used with supported elements (such as an <input> ), it fires the element's click event. This event then bubbles up to elements higher in the document tree (or event chain) and fires their click events.

How do I trigger a click event without clicking?

If you want native JS to trigger click event without clicking then use the element id and click() method of JavaScript.

What is trigger event in jQuery?

The trigger() method triggers the specified event and the default behavior of an event (like form submission) for the selected elements. This method is similar to the triggerHandler() method, except that triggerHandler() does not trigger the default behavior of the event.

What is the jQuery method for attaching a custom event to an element?

bind() method is used for attaching an event handler directly to elements. Handlers are attached to the currently selected elements in the jQuery object, so those elements must exist at the point the call to . bind() occurs.


1 Answers

You could use the .trigger() method:

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

or simply:

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

which would be the same.

like image 178
Darin Dimitrov Avatar answered Oct 05 '22 05:10

Darin Dimitrov