The $ .map () method applies a function to each element in an array or object and maps the results to a new array.
$(".class1").parent().map(function() {
return this.id;
})
.get()
.join();
This will return "id1, id2".
In the callback function, this refers to the current DOM element for each iteration. A function can return a single data item or an array of data items that need to be inserted into the result set. If the array is returned, elements inside the array are inserted into the set. If the function returns null or undefined, the element will not be inserted.
source
share