[英]Check, with jQuery, if an element is the first thing in another element
Is there a way to check if a child div
is the first item of the parent div
? 有没有一种方法可以检查child div
是否是parent div
的第一项?
For example: 例如:
<div id="parent">
Some text <--------- not the first thing in the div
<div id="child"></div>
</div>
Or 要么
<div id="parent">
<div id="child"></div> <--------- is the first thing in the div
Some text
</div>
Something like 就像是
var isFirst = $('#child').is($('#parent').contents().filter(function () {
return this.nodeType != 3 || $.trim(this.nodeValue) != ''
}).first())
There are few conditions to check 需要检查的条件很少
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.