开发者

jQuery 1.3.2 remove empty values

Hello I use this code to remove empty input text fields from my form:

 $('input:text[value=\"\"]', '#submForm').remove();

How do I achieve the same but with empty dropdown values like the below one?

<select><option value=""></option><开发者_如何学C;/select>

I need to remove the empty dropdown with the jQuery remove();

How do I do that?

Thank you!


$('select option[value=""]').remove();

Demo: http://jsfiddle.net/trXp8/

Or, you mean in between the option tag, then:

$('select option:empty').remove();

Demo: http://jsfiddle.net/X6BKA/

EDIT:

Okay. So you're referring to a multiple selection? Then this will do:

$('select option:not(:selected)').remove();

This will remove the options that have not been selected.

Demo: http://jsfiddle.net/Y4RZj


how about this (I don't think you can use it with the attributes because the value is on the option. Do you want to remove the option or the select item?

    $("select").each(function(){
      if($(this).val() == "")
         $(this).remove();
     });
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜