Triggering Events Manually in jQuery

$("span").mouseenter(); $("#myButton").click(); $("input.bigText").trigger({'type':'keypress', 'charCode':13});

jQuery objects have methods such as click() and dblclick() that correspond to many of the event types that you can call directly. Form elements add additional methods such as blur(), focus(), keypress(), keydown(), and keyup() that can be called to trigger specific events. For example, the following statement triggers the click event for all <span> elements:

$("span").click();

jQuery also provides a way to trigger events while specifying the values of the event object using the trigger() method. There are two different syntaxes for the trigger() method, as listed ...

Get jQuery and JavaScript Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.