I'm using jQuery to append new <option> tags to a <select> field, and in some cases I need to remove those options without knowing the values of them.
Is it possible to remove all the options that were created by jQuery whilst leaving the original options intact?
The only way I can think of doing it is by checking they're not the values I want to keep. Hopefully is there an easier, quicker, way?
Once elements are inserted into the DOM they are all equal; there is no magic "dynamically created" flag that you can check.
Of course you can always create your own methods to do so. For example, you can add a "data-dynamic" HTML attribute or a dynamic CSS class to the dynamically created options and then filter based on that.
You can add a property to the tags and filter on that. For example you can make them part of a class appended and delete them that way. See for an example this fiddle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With