Removing Option Groups
Can anyone please explain why jQuery works on the original code but deletes all the option for my code.
I have multiple of the exact same select menu so that's why I have it setup for the concat to put in the counter. But why does it work for the original and not mine??? I have been pouring over code and examples and can't see why.
In your example, the
option elements are actually inside of the
optgroup. They aren't in the first example. Take a look at http://jsfiddle.net/frJEq/47/ for comparison.
If you plan to wrap the elements inside the option group, you might find the
unwrap() function more convenient: http://jsfiddle.net/frJEq/48/
Thank you so much Jeremy. I had tried to experiment with the unwrap() function, but I didn't think about doing the each part so I was just unwrapping the whole thing to just the text nodes of the options. By any chance is there a way to do this with just pure JS? I can load in the jQuery library, but as of now, I have written my entire program in pure JS and think it is a little silly to just call one function. I am pulling in a few different libraries, so it's no biggie, but also curious. Thanks in advance.
Sure. Take a look at the below question.
You'd just have to do a loop and everything would work out.