i'm messing around with arrays and have a very basic question. lets say i have this html-markup:
<div id="1" style="width: 50px; height: 50px; background-color: #ff0; display: none;"></div>
<div id="2" style="width: 50px; height: 50px; background-color: #ffc; display: none;"></div>
<div id="3" style="width: 50px; height: 50px; background-color: #fcc; display: none;"></div>
and create the following array:
var testArr = ['$("#1")', '$("#2")', '$("#3")'];
why i cant execute the following function to work:
function showArr() { testArr[2].show();
};
showArr();
therefore shouldn't #3 get displayed?
thanks
var elems = $('#1, #2, #3')and then based on the order in the DOM you select what to show, likeelems.eq(2).show(), you don't stick elements in an array unless you have a really good reason to do so, and this doesn't look like it is such a reason. And you shouldn't use just a number for ID's.ids in the array, you could use the (fairly-horrible) approach here: (horrible) demo (don't seriously consider using this).