title: Jquery ID selector doesnt work with a variable
body: <p>I've read a billion questions like this, but never found an answer yet.</p>
  
  <p>Anyway, when I type</p>
  
  <pre><code>var variableContainingID = "header";
  var div = $("#"+variableContainingID);
  </code></pre>
  
  <p>It returns 'undefined'</p>
  
  <p>But when I type </p>
  
  <pre><code>var variableContainingID = "header";
  var div = $('[id^="'+variableContainingID+'"]');
  </code></pre>
  
  <p>It works fine. 
  Any ideas why?</p>
  
  <p>UPDATE</p>
  
  <pre><code>var json = '{"divs":['
  var children = $(".parent_container &gt; div");
  var idArray = [];
  var numArray = [];
  for (var x=0; x&lt;children.length; x++) {
      var eleid = $(children[x]).attr("id");
      idArray.push('"'+eleid+'"');
      numArray.push(x+1);
  }
  var idString = idArray.join(",");
  var numString = numArray.join(",");
  json += idString;
  json += '],"number":['+numString+']}';
  var obj = JSON.parse(json);
  for (x in obj["divs"]) {
      var div = $('[id^="'+obj["divs"][x]+'"]');
  }
  </code></pre>
  
  <p>Do you think the double quotes could be throwing it off?</p>