簡體   English   中英

隱藏沒有類和id屬性的html表2的第一行

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

我在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" );

但沒有結果...請幫助。

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

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

使用選擇器:nth-child(2)解決方案僅在第二個<table>是其父級的第二個子級時才有效,並將選擇每個 t <table>作為其父級的第二個子級。

調整后的cf注釋(jsfiddle也已修改)

看到這個的jsfiddle$('table').eq(1).find(tr:first').hide();

據我了解(根據OP對@DavidThomas的回答的評論),該表位於iframe 您需要先獲取該框架的內容,例如

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

jsFiddle顯示了它的工作原理。

嘗試這個 :

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

您可以使用nth-child和jQuery hide

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM