Reputation: 424
I have a list of n number of items that can be displayed. Class historyList is for styling, class projYear is only used to get the value.
<tr class="uniqueProject">
<td class="historyList projYear" style="width: 4em;">2011</td>
</tr>
Within in this list I can have x number of years. Each new year would repeat the code above. Currently I have 2011, 2012, 2013, 2014, 2015, 2016. This list will grow over time.
To grab the values within projYear, I have used $('.projYear').html()
. Unfortunately, this only returns the first on the list of 2011
Question: How can I use jQuery to place each of the years into an array? (i.e. [2011, 2012, 2013, 2014, etc])
Upvotes: 0
Views: 80
Reputation: 104775
Easy with .map
var years = $('.projYear').map(function() {
return $(this).text();
}).get();
Upvotes: 3