隐藏没有class和id属性的html表2的第一行

Hide first row of html table 2 having no class and no id attributes

本文关键字:一行 html class 属性 id 隐藏      更新时间:2023-09-26

我有两个html表在iframe标签,没有类和id属性。我试图使用jQuery找到第二表第一行和隐藏它?我的表格是这样的:注意:基本上我有两个表,这两个表都在iframe标签内。我需要隐藏第二个表的第一行吗?

<table>
  <tr>
        <td> 1 </td>
         .
         .
         .
 </tr> 
</table>

我需要隐藏下面表格的第一行:

<table>
   <tr>
     <td> This row i need to hide() </td>
   </tr>
  </table>

我已经尝试了很多方法,像这样:

      $( "table[1] tr:first" ).css("display", "none" );

但是没有结果…请帮助。

假设<table>元素不是兄弟元素,我建议:

$("table").eq(1).find("tr:first").hide();

使用选择器:nth-child(2)的解决方案将只工作,如果第二个<table>是其父的第二个孩子,并将选择 t <table>是其父的第二个孩子。

调整cf注释(jsfiddle也修改了)

查看jsFiddle查看$('table').eq(1).find(tr:first').hide();

据我所知(从OPs评论@DavidThomas的回答),表驻留在iframe中。首先需要获取该框架的内容,比如

    var framebody = $($('iframe')[0].contentDocument.body)
       ,frameSecondTable = framebody.find('table').eq(1);

jsFiddle显示了它的工作原理

试试这个:

 $( "table:nth-child(2) tr:first" ).css("display", "none" );

可以使用n -child和jQuery hide

$( "table:nth-child(2) tr:first" ).hide();