get row with className

后端 未结 6 1443
甜味超标
甜味超标 2021-01-27 01:24

How can you get the first row in a table with a specific className?

var rows = $(\'tr\', tbl);
相关标签:
6条回答
  • 2021-01-27 01:50

    var row = $("tr.className:first", tbl); should do the trick.

    0 讨论(0)
  • 2021-01-27 01:52

    You can use the :first selector along with the class selector,

    Try this:

    var rows = $('tr.someclass:first', tbl);
    
    0 讨论(0)
  • 2021-01-27 02:04

    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.

    0 讨论(0)
  • 2021-01-27 02:08

    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
    
    0 讨论(0)
  • 2021-01-27 02:11
    var firstRow = $('tr.classname:first', tbl)
    
    0 讨论(0)
  • 2021-01-27 02:16
    var rows = $('tr.classname:first', tbl);
    

    or

    var rows = $('tr.classname', tbl).first();
    

    Docs here: http://api.jquery.com/category/selectors/

    0 讨论(0)
提交回复
热议问题