You're starting with a string containing some HTML, stored in your txt
variable. When you call $(txt)
you're creating a jQuery object containing the elements defined in that HTML string, which is completely separate from your txt
variable. You can then manipulate (in this case attempt to remove) elements, but since it's completely separate from txt
the changes aren't going to be reflected in it.
If you want to change the value of txt
to be something else, you'll need to assign that value back to it, possibly like so (you mentioned that calling .text()
gave you what you expected/wanted to see):
txt = $(txt).find("select option[value='" + $(this).attr("id") + "']").remove().text();