JQuery does not depend on function of another control

I have the following code:

$(serialNumbersDDL).children("option:gt(0)").remove();

      

It will remove all options except the first. Now I need to remove all parameters except the first, and also not remove the parameter whose value is equal to the label text. How can I tell what is with writing a limited amount of code?

+3


source to share


2 answers


try it



$("option:not(':first')",serialNumbersDDL).filter(function(){
return $(this).val()!=$(this).text();
}).remove();

      

+2


source


I would try



$(serialNumbersDDL).children("option:gt(0)").not(function(){
    return $(this.labels).text() == this.value;
}).remove();

      

+1


source







All Articles