Deleting an option tag in DOM is not a problem for me, but now I have to delete an option Tag in a variable. This is what I have:
var txt = "<select name='example'><option value='1'>Test</option></select>";
$(txt).find("select option[value='" + $(this).attr("id") + "']").remove();
The selector seems to be right, i’ve debugged it with text() and it gives me the right value. But the variable txt doesn’t change – what did I do wrong?
Create a jQuery selector to start with to save yourself having to constantly cast it again into one.
In your find you also don’t need to specify
selectagain as you are executing.find()on the select.For simplicity I cached the result of the
.find()into a nother selector variable before removing it.The below works fine. Well, it works fine if I use
1instead of$(this).attr("id")as I don’t know what you are refering to with$(this).Working DEMO