stack stack - 10 months ago 48
Javascript Question

How to make a array of html content?

Here is the HTML:


Now I need to make an array of second column of that table like this:

var arr = ['one', 'two'];

How can I do that?

I can select the table like this
and get its content like this:
$('table td+td')
, but I don't know how can I make an array of them.

Answer Source

You can use :nth-child() to select second td and map() to return array DEMO

var arr = $('table td:nth-child(2)').map(function() {
  return $(this).text();