View Full Version : Removing Option Groups

07-12-2014, 12:00 AM
Can anyone please explain why jQuery works on the original code but deletes all the option for my code.

Original Code:

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.


07-12-2014, 03:47 AM
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/

07-13-2014, 02:15 AM
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.


07-13-2014, 06:23 AM
Sure. Take a look at the below question.


You'd just have to do a loop and everything would work out.