开发者

Remove Particular Option from select Tag

开发者 https://www.devze.com 2023-02-11 14:58 出处:网络
I have the following combobox and I want to remove the option which value is Null (value=\'\') by using jQuery

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消