get row with className
How can you get the first row in a table with a specific className?
var rows = $('tr'开发者_运维技巧, tbl);
var rows = $('tr.classname:first', tbl);
or
var rows = $('tr.classname', tbl).first();
Docs here: http://api.jquery.com/category/selectors/
var firstRow = $('tr.classname:first', tbl)
You can use the :first
selector along with the class selector,
Try this:
var rows = $('tr.someclass:first', tbl);
var row = $("tr.className:first", tbl);
should do the trick.
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
精彩评论