我有一个带有 id='tips'
的 div。它有多个 child 。我需要做的是我想用 id='tips'
获取一个 div 的子元素,它有它的样式,top < 10px。这是代码片段。
<div id="tips">
<div style="top: 5px; left: 150px;">
Required Div
<span class="arrow"></span>
</div>
<div style="top: 15px; left: 150px;">
Not-Required Div
<span class="arrow"></span>
</div>
<div style="top: 45px; left: 150px;">
Child3
<span class="arrow"></span>
</div>
</div>
Only one div child div with top<10px exists.
最佳答案
使用filter()
:
var $child = $("#tips div").filter(function() {
return parseInt($(this).css("top"), 10) < 10;
});
// you can do as needed with the element(s) here, this is just an example
$child.css("color", "#C00");
关于javascript - Jquery 让 child 有条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10718662/