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 adynamicCSS class to the dynamically created options and then filter based on that.