jQuery select only tr/td in main table, not nested tables.

前端 未结 4 1806
感情败类
感情败类 2021-02-07 08:23

I currently have a table with a nested table in it:

   

        
                      
相关标签:
4条回答
  • 2021-02-07 09:00

    You use the > selector to target only the direct descendant of an element. You have to target the implicit tbody element inside the table also:

    $('#report>tbody>tr.odd')
    
    0 讨论(0)
  • 2021-02-07 09:08

    You want

    $("#report>tr")
    

    The > means direct descendant (child) rather than any descendant.

    0 讨论(0)
  • 2021-02-07 09:12

    with this solution it does not matter whether you have a tbody tag in between:

    $('table').find('tr:first').parent().children()
    
    0 讨论(0)
  • 2021-02-07 09:19

    Use the child selector > to only select those tr elements that are a child of the report table’s tbody, for example:

    $("#report > tbody > tr.odd")
    
    0 讨论(0)
提交回复
热议问题