Omu
Omu

Reputation: 71208

get an array of "val" attributes values from the rows of a table

<table id ='t1'>
<tr val='1'></tr>
<tr val='2'></tr>
<tr val='3'></tr>
<tr val='4'></tr>
<table>

how to get from this an array = 1,2,3,4

Upvotes: 3

Views: 939

Answers (2)

Artem Barger
Artem Barger

Reputation: 41232

This should work:

$.map( $( "table#t1 tr"), function( item) { return $(item).attr("val");})

Upvotes: 0

Nick Craver
Nick Craver

Reputation: 630409

You can use .map(), like this:

var arr = $("#t1 tr").map(function() { return $(this).attr("val"); }).get();

You can test it out here.

Upvotes: 7

Related Questions