Triggering Events
The event handlers you register are automatically invoked when the
user uses the mouse or keyboard, or when other kinds of events occur.
Sometimes, however, it is useful to be able to trigger events manually.
The simple way to do this is to invoke one of the event registration
methods (like click() or mouseover()) with no argument. Just as many
jQuery methods serve as both getters and setters, these event methods
register an event handler when invoked with an argument, and trigger
event handlers when invoked with no arguments. For example:
// Act as if the user clicked the Submit button
$("#my_form").submit();
The submit() method in the line
above synthesizes an Event object and triggers any event handlers that
have been registered for the “submit” event. If none of those event
handlers returns false or calls the
preventDefault() method of the Event
object, the form will actually be submitted. Note that events that
bubble will do so even when triggered manually. This means that
triggering an event on a selected set of elements may also trigger
handlers on the ancestors of those elements.
It is important to note that jQuery’s event triggering methods
will trigger any handlers registered with jQuery’s event registration
methods, and they will also trigger handlers defined on HTML attributes
or Element properties such as onsubmit. But you cannot manually trigger
event handlers registered with addEventListener() or attachEvent() (those handlers will still be invoked ...