0

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])

1 Answer 1

3

Easy with .map

var years = $('.projYear').map(function() {
    return $(this).text();
}).get();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.