Javascript 如何在div中选择没有选择器的元素
我有一块无法直接访问的HTML,但想用CSS或Javascript隐藏某些部分。下面是它的外观,以及我试图隐藏的部分:Javascript 如何在div中选择没有选择器的元素,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我有一块无法直接访问的HTML,但想用CSS或Javascript隐藏某些部分。下面是它的外观,以及我试图隐藏的部分: <div id="container"> <h3>Title here</h3> <table class="cool"> <tr><td>hide this</td></tr> <tr><td>hide thi
<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>
标题在这里
把这个藏起来
把这个藏起来
不要隐瞒这件事
把这个藏起来
更多的废话
保留所有这些
保留所有这些
把这些都藏起来
把这些都藏起来
这将实现问题中所示的精确布局。但是,对同一类的行数或表数的任何更改都可能导致该类失败
var $tables = $('table.cool');
$tables.eq(0).find('tr').not(':eq(2)').hide();
$tables.eq(2).children().hide();
还是最后一张桌子藏起来
$tables.eq(2).hide();
如果您想完全删除这些行,请将remove()
替换为hide()
这将实现问题中所示的精确布局。但是,对同一类的行数或表数的任何更改都可能导致该类失败
var $tables = $('table.cool');
$tables.eq(0).find('tr').not(':eq(2)').hide();
$tables.eq(2).children().hide();
还是最后一张桌子藏起来
$tables.eq(2).hide();
如果您想完全删除这些行,请将remove()
替换为hide()