jquery - Add change event to element added after page load -
i'm using ajax add #it_selectcatlvl2
element in div #div_it_selectcatlvl2
, see when change value #it_selectcatlvl2
script doesn't work.
code:
$('#it_selectcatlvl2').change(function() { if($(this).val() > 0){ $('#it_submit').removeattr("disabled"); }else{ $('#it_submit').attr("disabled", "disabled"); } }); <div id="div_it_selectcatlvl2"> <select class="n_selectpath" style="" name="it_selectcatlvl2" id="it_selectcatlvl2"> <option value="0">change</option> <option value="1">one</option> </select> </div>
use this:
$('#div_it_selectcatlvl2').on('change', '#it_selectcatlvl2', function() { $('#it_submit').prop('disabled', !(this.value > 0)); });
your problem occurs because you're attaching change event element doesn't exist yet.
the code i've used executed when change event bubbles #div_it_selectcatlvl2
, has been triggered element id #it_selectcatlvl2
.