How to get only direct child elements by jQuery function

后端 未结 5 1325
长情又很酷
长情又很酷 2020-12-13 03:27

I have a table structure like this:


  
    
      
        ...
      
        

        
5条回答
  •  情歌与酒
    2020-12-13 03:42

    This is exactly the reason why one should be careful with nesting tables. I really hope that you use them for data and not page layout.

    Another issue that will probably ruin your day is using CSS selectors on nested tables... you basically have the same issue - you are unable to select TR elements of the outer table without selecting those inside the inner table, too. (You cannot use the child selector because it is not implemented in IE6)

    This should work:

    $("#table1 > tbody > tr")
    

    However, I recommend that you hardcode the TBODY element, since you should not rely on the browser to create it for you.

提交回复
热议问题