views:

25

answers:

1

i have a number of divs with the class="mydiv"

each of these divs also has an attribute id which is set to a number

i want to basically say (pseudo code)

select all divs with class = "myDiv"
loop through them and get the id attribute
combine all ids into a list and return an array of these integers

is this the best way of doing that?

 var ids = new Array();
 $(".myDiv").each(function (i) {
    var id = $(this).attr('id');
    ids[i] = id;
  });
+2  A: 
$('.myDiv[id]').map(function() { return this.id });

will give you an array like object which you can treat as an array ( for loop ) of ids.

meder
That'll make a list of strings. I'm guessing the original poster wants a list of ints, so I'd update to `return Number(this.id)`.
darkporter