Passing multiple ID attributes to an array

Passing multiple ID attributes to an array

Hi all,
I would like to grab the id attribute of every element with a specific class, and append the id names to a div.

Something a bit like:

  1. // select everything with a class of widget, and pass all the ids to an array
  2. var idArray =  $('.widget').attr('id').toArray();
  3.            
  4.  // get each id in the array and seperate by a comma
  5. var idPrint = $.each(idArray, function(i, val) {
  6. (val + "," );
  7. });
  8.            
  9.  // append results to target div
  10.  $("#targetDiv").append(idPrint);
I've been googling for an answer all day, and have tried a few different approaches, but nothing is working yet, any help much appreciated.