gpt4 book ai didi

jquery - 检查几个高度并隐藏高元素容器父元素

转载 作者:太空宇宙 更新时间:2023-11-04 14:13:11 25 4
gpt4 key购买 nike

有一个.blog DIV,它包含三个article,每个都有一个h1h4,当h1 符合 .blog 的宽度,它分成两行,所以会有更高的高度(高于 50px)

<div class="blog">
<article>
<h1>Hello There</h1>
<h4>Description 1</h4>
</article>
<article>
<h1>Hello There</h1>
<h4>Description 2</h4>
</article>
<article>
<h1>Hello There I'm a long text who have a more than 50px height</h1>
<h4>Description 3</h4>
</article>
</div>

当它的高度超过 50px 时,我想隐藏它的 h4

var max=50;
$('.blog article').find('h2').each( function (){
if($(this).height()>max)
$("article h4").hide();
});

是的,我知道它会隐藏所有三个 h4,所以我应该只隐藏高大的 h1 容器文章 h4 >?

最佳答案

var max=50;
$('.blog article').find('h1').each( function (){
if($(this).height()>max)
$(this).next('h4').hide();
});

关于jquery - 检查几个高度并隐藏高元素容器父元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20574698/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com