JQuery, select first row of table

前端 未结 6 1051
清歌不尽
清歌不尽 2020-12-30 00:26

I\'ve used JQuery to add a \"image\" button to a few rows in a table. I used the following code:

$(\"#tblResults tr:nth-child(1) td.ResultsHeader span.gridRC         


        
6条回答
  •  余生分开走
    2020-12-30 00:58

    Actually, if you try to use function "children" it will not be succesfull because it's possible to the table has a first child like 'th'. So you have to use function 'find' instead.

    Wrong way:

    var $row = $(this).closest('table').children('tr:first');
    

    Correct way:

     var $row = $(this).closest('table').find('tr:first');
    

提交回复
热议问题