I'm trying to allow a user to enter in a number (i.e. 3 in the first div below) that will decide which div's to show in an output. I created an array of id's (or so I thought) based on the number entered. When I alert the array the id's look correct but for some reason when I try and show them in the function below nothing happens. This is very similar to this post: how to loop through an array of jquery objects and .hide() each of them but I can't re-create it. Any help would be greatly appreciated. Here's a fiddle: http://jsfiddle.net/dbeau79/4KzuN/
<div id="variable_1">3</div>
<div id="jinja_1" class="jinja">I'm Jinja 1</div>
<div id="jinja_2" class="jinja">I'm Jinja 2</div>
<div id="jinja_3" class="jinja">I'm Jinja 3</div>
<div id="jinja_4" class="jinja">I'm Jinja 4</div>
<div id="jinja_5" class="jinja">I'm Jinja 5</div>
<div id="jinja_6" class="jinja">I'm Jinja 6</div>
$('.jinja').hide();
var varStart = 1;
var varEnd = $('#variable_1').text();
var arr = [];
while (varStart <= varEnd) {
arr.push("'#jinja_" + varStart++ + "'");
}
$.each(arr, function () {
//alert(this);
$(this).show();
});