I have the following code (playing with some selects).
After the first change function, the second change function does not work:
jQuery('.toPopSelect').change(function(){
console.log("hey");
});
I think it's because the first change function replaces some html and jQuery can't select the .toPopSelect class after.
Any idea why is this happening? is there a way around it?
<select class="theSelect">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<div class="toPopulate">
<select class="toPopSelect">
<option value="1">1</option>
<option value="2">2</option>
</select>
</div>
jQuery(document).ready(function(){
jQuery('.theSelect').change(function(){
jQtoPopulate = jQuery('.toPopulate');
jQtoPopulate.empty();
jQtoPopSelect = jQuery('.toPopSelect');
v = jQuery(this).val();
if ( v == 1) {
console.log("ues")
jQtoPopulate.html('<input type="text" size="60"><\/input>');
} else {
jQtoPopulate.html('<select class="toPopSelect"><option value="1">1<\/option><option value="2">2<\/option><option value="3">3<\/option><option value="4">4<\/option><option value="5">5<\/option><\/select>');
jQtoPopSelect.append('<option value="6">6<\/option>');
}
});
jQuery('.toPopSelect').change(function(){
console.log("hey");
});
});
Any ideas?