Reputation: 2527
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>
Upvotes: 13
Views: 18794
Reputation: 43077
Just call change().
$(".cl_preAction").change();
Bind an event handler to the "change" JavaScript event, or trigger that event on an element.
Upvotes: 32
Reputation: 1786
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."
Upvotes: 4