Skip to content
Advertisement

Not able to remove option in cloned select

I have an issue with removing a cloned option that I created. I can remove the original option, but nothing is removed from the clone.

JavaScript
JavaScript

What is wrong with this code? I tried several methods but still failed. Thanks for helping me.

Advertisement

Answer

The issue is because you’re selecting the option elements. As such there is no root node in the jQuery object to remove() the option elements from. Trying to find() instead of filter() that collection is another issue, but not the main problem.

To fix this, clone() the entire select element and then find() and remove() the target option. Try this:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement