Although this question may have been answered before, I couldn't find a specific solution.
Imagine I have the following div elements...
<div class="listings-area">
<div itemtype="http://schema.org/Product" itemscope="">
<a class="listing" data-id="D_2781467">blah blah </a>
some more blahj blah text here
</div>
<div itemtype="http://schema.org/Product" itemscope="">
<a class="listing" data-id="D_2781445">blah blah </a>
some more blahj blah text here
</div>
.......................
.......................
</div>
I am looking to extract all the data-id attributes from these elements, store them in an array, and then pass them along in a JavaScript cookie
If I try something like
$('a.listing').attr('data-id')
I only obtain the data id of the first element. How can I retrieve all the data ids and add them to an array?