Reputation: 7969
I have optgroup in select menu, I want get rid of from it. I am using jquery unwrap method to get it done but it is removing whole select menu. here is fiddle
$(function(){
$('select').find('option').not(':first').parent().unwrap()
})
<select>
<option>select</option>
<optgroup label="state">
<option>new york</option>
</optgroup>
<optgroup label="country">
<option>us</option>
</optgroup>
</select>
Upvotes: 2
Views: 890
Reputation: 28397
$('select').find('option').not(':first').unwrap();
You have to unwrap the option not the parent of the option!
Your updated fiddle: http://jsfiddle.net/Lq5dN/10/
Upvotes: 3
Reputation: 1700
try:
$(function(){
$('select').find('optgroup option').unwrap()
})
Demo Fiddle
Upvotes: 2