Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

programmatically trigger to .change event with jquery/javascript?

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>
like image 283
Mustapha George Avatar asked Nov 10 '11 21:11

Mustapha George


2 Answers

Just call change().

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

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

like image 87
jrummell Avatar answered Sep 19 '22 22:09

jrummell


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

like image 20
malletjo Avatar answered Sep 22 '22 22:09

malletjo