I am trying to gather a list (array) of ids in a sector
<div id="mydiv">
<span id='span1'>
<span id='span2'>
</div>
$("#mydiv").find("span");
gives me a jQuery object, but not a real array;
I can do
var array = jQuery.makeArray($("#mydiv").find("span"));
and then use a for loop to put the id attributes into another array
or I can do
$("#mydiv").find("span").each(function(){}); //but i cannot really get the id and assign it to an array that is not with in the scope?(or can I)
Anyhow, I just wanna see if there is a shorthand in jQuery to do that;
Yes, you can!
This is the beauty of closures.
Note that while you were on the right track, sighohwell and cletus both point out more reliable and concise ways of accomplishing this, taking advantage of attribute filters (to limit matched elements to those with IDs) and jQuery’s built-in
map()function: