← Back to Index

.trigger()

Execute all handlers and behaviors attached to the matched elements for the given event type.

Examples

1. Trigger basic event

$('button').on('click', () => console.log('Clicked'));
$('button').trigger('click');

Result

// Console Output:
"Clicked"

2. Trigger with data

$('button').on('click', e => console.log(e.detail._sr_extra));
$('button').trigger('click', { foo: 'bar' });

Result

// Console Output:
{ foo: "bar" }

Parameters

Parameter Type Description
eventType string One or more space-separated event types to trigger.
extraParameters any Additional parameters to pass along to the event handler. Accessible via event.detail._sr_extra.

Returns: The original SR object for chaining.