I have the following combobox and I want to remove the option which value is Null (value='') by using jQuery
<option value=''>--Select--</开发者_如何学Gooption>
<option value ='1'>One</option>
<option value ='2'>two</option>
<option value ='3'>three</option>
<option value ='4'>four</option>
Expected combo option:
<select name='x' id='x'>
<option vlaue=''>--Select--</option>
</select>
If I understand you correctly as saying that you want to remove all options for which value is not null, then the following will work:
$("#x").children("option").not("[value='']").remove();
If it's the reverse, then:
$("#x").children("[value='']").remove();
But first you have to fix your misspellings in your code:
<select name='x' id='x'>
<option value=''>--Select--</option>
<option value='1'>One</option>
<option value='2'>two</option>
<option value='3'>three</option>
<option value='4'>four</option>
</select>
Note that value
and /select
were misspelled in your example, and that'll keep any code from working.
精彩评论