https://jsfiddle.net/Lyuz233f/1/
我只想隐藏我的上一个hr
,但我不明白为什么我的所有hr
都被隐藏了:
<div class="container">
<div class="row">
<div class="col-md-12 text-center" style="margin-bottom:50px">
<h4 class="uppercase mb16">Something</h4> </div>
</div>
<div class="row">
<div class="col-md-12 text-center">
<div class="post-snippet mb64" style="margin-bottom:0px">
<div style="text-align:justify">
<p>one</p>
</div>
<hr/>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 text-center">
<div class="post-snippet mb64" style="margin-bottom:0px">
<div style="text-align:justify">
<p>two</p>
</div>
<hr/>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 text-center">
<div class="post-snippet mb64" style="margin-bottom:0px">
<div style="text-align:justify">
<p>three</p>
</div>
<hr/>
</div>
</div>
</div>
</div>
<script>
$( ".container hr:last-child" ).css({ display:"none"});
</script>
答案 0 :(得分:5)
答案 1 :(得分:3)
您的代码无效,因为当您尝试选择给定父级的last-child
元素时,这将查找该父元素的直接后代,在本例中为.container
元素。尝试选择.row
中的最后一个.container
,这将举例说明我刚才所说的内容:
$( ".container .row:last-child hr" ).css({ display:"none"});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<div class="row">
<div class="col-md-12 text-center" style="margin-bottom:50px">
<h4 class="uppercase mb16">Something</h4> </div>
</div>
<div class="row">
<div class="col-md-12 text-center">
<div class="post-snippet mb64" style="margin-bottom:0px">
<div style="text-align:justify">
<p>one</p>
</div>
<hr/>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 text-center">
<div class="post-snippet mb64" style="margin-bottom:0px">
<div style="text-align:justify">
<p>two</p>
</div>
<hr/>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 text-center">
<div class="post-snippet mb64" style="margin-bottom:0px">
<div style="text-align:justify">
<p>three</p>
</div>
<hr/>
</div>
</div>
</div>
</div>
答案 2 :(得分:1)
您也可以使用此解决方案作为替代
$(".container hr:last" ).hide();
OR
$( ".container .row:last-child hr" ).hide();