Reputation: 45737
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></select>
I need to remove the empty dropdown with the jQuery remove();
How do I do that?
Thank you!
Upvotes: 2
Views: 5166
Reputation: 35301
$('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
Upvotes: 6
Reputation: 10243
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();
});
Upvotes: 1