I can’t seem to get variables working within selectors in jQuery. This is a really simple but annoying bug! See this jsFiddle for an example:
The following does not work:
var folder_id = "folder";
$("#selects select[name='" + folder_id + "']").append('<span>Hi></span>');
Markup:
<div id="selects">
<select name="folder_id">
<option>hey</option>
</select>
</div>
Answering the question you actually asked (but see also below):
You’re telling it to find a
selectwith thenamefolder, notfolder_id. But yourselecthas the namefolder_id.So either change the code:
Updated fiddle (but again, see below under the break)
…or change the markup:
Updated fiddle
But note that you’re trying to append a
spanto aselect, which is invalid markup and won’t work.selectelements cannot containspans(onlyoptionandoptgroupelements). If you meant to put it after theselect, useafter:Another fiddle