O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required