Hi I’m trying to empty an input select with this code:
$(document).on('change', '#firstselect', function(){
if($('#secondselect').length > 1){
$('#secondselect').empty();
var html = '<option value="9997" selected="selected">ESCOJE UNA SUBCATEGORIA</option>'
$('#subcategoria').html(html);
}
});
Now it works fine with 0 but why if its 1 it does not?
Note: At first the select has the option that is shown which is added after is emptied and when the first select is changued it is filled with info from a server but I did not put that code since it’s not relevant.
EDIT: It looks that if you do change to >= it does work but if it’s >=2 does not why?
You are comparing the length of the
selectelement and not the number ofoptionelements inside it. So there’s only ever 1 select element that matches that ID.