Darren
Darren

Reputation: 793

Can I invoke an event handler programmatically?

I would like to call the following event handler from within another function without having to split the code out into another function:

$('#welcome select').change(function () {...});

Is this possible?

Upvotes: 1

Views: 166

Answers (3)

Halcyon
Halcyon

Reputation: 57719

function handler() {
    // do stuff
}
$('#welcome select').change(handler);

handler();

Upvotes: 0

Ilia G
Ilia G

Reputation: 10211

Take a look at the trigger. This seem to be what you looking for.

Upvotes: 2

aziz punjani
aziz punjani

Reputation: 25776

Sure, you can trigger the change event.

$('#welcome select').trigger('change'); 

Upvotes: 7

Related Questions