I'm getting the select html and want to give it a new name, this is what I'm trying at the moment:
var sel = $("#rmFilesListSelect").html();
$(sel).attr({name: "item_files[fid-123]"});
$("#someTable tbody").append("<tr><td>" + sel + "</td></tr>");
However, this does not work as I would expect it. Instead it inserts the old id from #rmFilesListSelect. What am I missing here?
EDIT: I have ended up using a combination of several comments (including outerHTML() from https://stackoverflow.com/a/5259788/1231450, linked by bitfiddler)
var sel = $("#rmFilesListSelect").clone();
$(sel).attr({name: "item_files[fid-123]"});
$("#someTable tbody").append("<tr><td>" + $(sel).outerHTML() + "</td></tr>");
Thank you very much!