get row by index

前端 未结 9 914
名媛妹妹
名媛妹妹 2020-12-17 16:35

how can you get a row by the index?

var rows = $(\'tr\', tbl);
rows.index(0).addClass(\'my_class\');
相关标签:
9条回答
  • 2020-12-17 17:22

    Use .eq().

    var rows = $('tr', tbl);
    rows.eq(0).addClass('my_class');
    

    ...or for your simple case, .first():

    rows.first().addClass('my_class');
    
    0 讨论(0)
  • 2020-12-17 17:25

    Using either the eq() function:

    rows.eq(0).addClass('my_class');
    


    Or the :eq() selector:

    $('tr:eq(0)', tbl).addClass('my_class');
    
    0 讨论(0)
  • 2020-12-17 17:29

    For the first element (index 0) the answer provided to your earlier question should be fine.

    For any nth element use eq selector

    e.g:

    var rows = $('tr:eq(8)', tbl);
    
    0 讨论(0)
提交回复
热议问题