Get an array of "val" attribute values โ€‹โ€‹from table rows

<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 array = 1,2,3,4

+3
source share
2 answers

You can use .map(), for example:

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

You can check it out here .

+7
source

This should work:

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

Source: https://habr.com/ru/post/1781433/


All Articles