隐藏没有类且没有id属性的html表2的第一行

时间:2014-08-17 16:04:25

标签: javascript jquery css html-table

我在 iframe 标记中有两个html表,没有class或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" );

但没有结果...... 请帮忙。

4 个答案:

答案 0 :(得分:3)

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

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

使用选择器:nth-child(2)的解决方案仅在第二个<table>是其父级的第二个子级时才有效,并且将选择每个 t <table>父母的第二个孩子。

答案 1 :(得分:1)

调整后的cf评论(jsfiddle也修改了)

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

jsFiddle

据我所知(来自OP对@DavidThomas回答的评论),该表位于iframe内。您需要先获取该帧的内容,例如

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

jsFiddle展示了它的运作方式。

答案 2 :(得分:0)

试试这个:

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

答案 3 :(得分:0)

您可以使用nth-child和jQuery hide

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