this is a followup of the previous
this works ! thanks !
even better is :
var myArr = $("#mytable tr").map(function (){
return parseInt(this.getAttribute("rowid")); // returns an array
});
so I get my array of integers instead of strings
can you explain me the difference between :
and
which gives completely different results !
I would like the same but some have a class=“active” attribute
I would like to get only the rowids of the that have this class=active
again, my javascript level is low enough I don’t have any idea how to proceed …
thanks.
my example table could be like this :
<table id="mytable">
<thead>
</thead>
<tbody>
<tr rowid="661">line6</tr>
<tr rowid="68" class="active">line8</tr>
<tr rowid="977">line7</tr>
<tr rowid="35" class="active">line3</tr>
</tbody>
</table>
I would like an array with [68] in it.
note: there can be more than one line with the active class in them.
I think the CSS selector matching what you want is “#mytable tr.active”.
seems you’re right Ricardo.
this
var myArr = $("#mytable tr.active").map(function (){
return parseInt(this.getAttribute("rowid")); // returns an array
});
works ! returns [68,35] on my example table
1 Like
Nice! =)
jQuery uses CSS selectors, so it’s a nice thing to learn (even if you don’t plan to spend too much time styling)