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:
- // select everything with a class of widget, and pass all the ids to an array
- var idArray = $('.widget').attr('id').toArray();
-
- // get each id in the array and seperate by a comma
- var idPrint = $.each(idArray, function(i, val) {
- (val + "," );
- });
-
- // append results to target div
- $("#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.