14

Is there a way to programmatically trigger to .change event with jQuery/javascript?

I want a piece of code that will fire a DOM change event for a select/option box such as the following:

<div data-role='fieldcontain' class='none'>
    <select name='ACTC' class='none cl_preAction' >
    <option data-location='S' value='001'>Fire</option>
    <option data-location='T' value='002'>Flood</option>
    <option data-location='T' value='003'>End Of World</option>
    </select>
</div>
1

2 Answers 2

33

Just call change().

$(".cl_preAction").change();

Bind an event handler to the "change" JavaScript event, or trigger that event on an element.

Sign up to request clarification or add additional context in comments.

Comments

4

You can trigger an event using the trigger function of jQuery.

$(".none select").trigger('change');

"Although .trigger() simulates an event activation, complete with a synthesized event object, it does not perfectly replicate a naturally-occurring event."

3 Comments

Think that wasn't the question ... trigger() to simulate and change() to capture the event.
Not quite the answer to the question, but of value to me on a related question, and google directed me here
calling change() without passing in a function runs trigger('change');.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.