2016-05-29 117 views
0

我有一塊HTML,我無法直接訪問,但希望用CSS或Javascript隱藏某些部分。下面是它看起來像和我試圖隱藏的部分:如何在div中選擇沒有選擇器的元素

<div id="container"> 
    <h3>Title here</h3> 
    <table class="cool"> 
     <tr><td>hide this</td></tr> 
     <tr><td>hide this</td></tr> 
     <tr><td>dont hide this</td></tr> 
     <tr><td>hide this</td></tr> 
    </table> 
    <h3>More nonsense</h3> 
    <table class="cool"> 
     <tr><td>keep all of this</td></tr> 
     <tr><td>keep all of this</td></tr> 
    </table> 
</div> 
<hr> 
<table class="cool"> 
    <tr><td>hide all of this</td></tr> 
    <tr><td>hide all of this</td></tr> 
</table> 
+0

'不能直接訪問'意味着你不能編輯html本身,比如手動添加類? – charlietfl

+0

@ user2181397閱讀「​​」中的文字。它告訴你要隱藏什麼而不是隱藏 – charlietfl

+0

你可以使用css來隱藏你的元素或java腳本。我沒有得到這個問題? – aghilpro

回答

3

這將執行問題中顯示的確切佈局。與同等級表中的行或數字的號碼的任何變化可能導致失敗雖然

var $tables = $('table.cool'); 

$tables.eq(0).find('tr').not(':eq(2)').hide(); 
$tables.eq(2).children().hide(); 

或最後一個表隱藏整個事情

$tables.eq(2).hide(); 

,如果你想完全擺脫那些行替代remove()hide()

DEMO