I use this: http://datatables.net/release-datatables/examples/api/select_row.html
Here is function return selcted rows:
function fnGetSelected( oTableLocal )
{
var aReturn = new Array();
var aTrs = oTableLocal.fnGetNodes();
for ( var i=0 ; i<aTrs.length ; i++ )
{
if ( $(aTrs[i]).hasClass('row_selected') )
{
aReturn.push( aTrs[i] );
}
}
return aReturn;
}
i do:
var arr = fnGetSelected(oTable);
this return me:
[tr.gradeA, tr.gradeA, tr.gradeA]
this is:
<tr class="gradeA even row_selected">
<td class=" sorting_1"><span class="my_values" test="aaa">Gecko</span></td>
<td>Camino 1.5</td>
<td>OSX.3+</td>
<td class="center">1.8</td>
<td class="center">A</td>
</tr>
<tr class="gradeA odd row_selected">
<td class=" sorting_1"><span class="my_values" test="bbb">Gecko</span></td>
<td>Netscape 7.2</td>
<td>Win 95+ / Mac OS 8.6-9.2</td>
<td class="center">1.7</td>
<td class="center">A</td>
</tr>
<tr class="gradeA even">
<td class=" sorting_1"><span class="my_values" test="bbb">Gecko</span></td>
<td>Netscape Browser 8</td>
<td>Win 98SE+</td>
<td class="center">1.7</td>
<td class="center">A</td>
</tr>
I add for this own span.my_values with attribute test.
Now i would like get all attribute test for this.
I try:
arr.each(function(index) {
console.log($(this).children());
});
but this return error: arr.each is not a function
How can i make it?
jQuery’s generic array looping function is
$.each, not a member ofArray.prototype, so:If you’d like to get the
testattribute of thespanwith class “my_values” inside the elements inarr, you can use$.map:…which gives you an array of the
testvalues.Side note 1: Since you’re using jQuery, which is inherently set-based, rather than having your
fnGetSelectedfunction return anArrayof matching elements, how ’bout having it return ajQueryobject?That creates a jQuery object containing all of the returned nodes, then filters it to only the ones with the class “row_selected” (as your original did) and returns it.
Then you can use it like this:
Side note 2: “test” is an invalid attribute for
spanelements, although browsers allow it. Look at usingdata-*attributes instead, e.g., “data-test” rather than “test”.