get row by index

前端 未结 9 931
名媛妹妹
名媛妹妹 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:18

    You could use the native rows[docs] property on the HTMLTableElement.

    $(tbl[0].rows[0]).addClass('my_class');
    

    As noted by @Felix, I've assumed that tbl is a jQuery object. If not, do this:

    $(tbl.rows[0]).addClass('my_class');
    

提交回复
热议问题