How can you get the first row in a table with a specific className?
var rows = $(\'tr\', tbl);
var row = $("tr.className:first", tbl);
should do the trick.
You can use the :first selector along with the class selector,
Try this:
var rows = $('tr.someclass:first', tbl);
If you keep the proprietary :first
selector out of it, you'll have a valid querySelectorAll
selector.
var rows = tbl.find('tr.someClass').slice( 0, 1 );
or
var rows = tbl.find('tr.someClass').eq( 0 );
Also, using the context parameter $( selector, context )
is just a slower way of using the find()[docs] method.
You can even use eq method of jquery if you want to loop through a list of elements.
var rows = $('tr.classname');
rows.eq(0);//first row
rows.eq(1);//second row
var firstRow = $('tr.classname:first', tbl)
var rows = $('tr.classname:first', tbl);
or
var rows = $('tr.classname', tbl).first();
Docs here: http://api.jquery.com/category/selectors/