jquery - convert attribute based on class selector to a list of ints

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;
  });
1
задан leora 9 September 2010 в 02:10
поделиться