如何使用jQuery选择第一个块级父级? [英] How to select first block level parent with jQuery?
本文介绍了如何使用jQuery选择第一个块级父级?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑以下标记:
<div id="0">
<h1 id="1">
<span id="2"><span id="3">lorem ipsum</span></span>
</h1>
</div>
如何使用jQuery查找span#3的第一个父级,该父级是块级(即具有display: block
)?在这种情况下,该值为h1#1
.
How can I find the first parent of span#3 that is of block level (i.e. has display: block
) using jQuery? In this case that would be h1#1
.
推荐答案
$("#3").parents().filter(function() {
return $(this).css("display") === "block";
}).first()
这篇关于如何使用jQuery选择第一个块级父级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文