Skip to main content
add markup
Source Link
T.J. Crowder
  • 1.1m
  • 201
  • 2k
  • 2k

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>​ 

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>'); 

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>​ 
Source Link
jacktheripper
  • 14.3k
  • 12
  • 62
  • 93

Variable in selector jQuery

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>');