View Full Version : Removing Option Groups
javacrypter
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:
http://jsfiddle.net/frJEq/
My Code:
http://jsfiddle.net/frJEq/43/
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.
Thomas
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/
javacrypter
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.
Thomas
Sure. Take a look at the below question.
http://stackoverflow.com/questions/11580292/removing-wrapper-div-without-jquery-raw-javascript
You'd just have to do a loop and everything would work out.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.