Reputation: 3215
Is there a way to check if a child div
is the first item of the 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>
Upvotes: 1
Views: 37
Reputation: 388316
Something like
var isFirst = $('#child').is($('#parent').contents().filter(function () {
return this.nodeType != 3 || $.trim(this.nodeValue) != ''
}).first())
There are few conditions to check
Upvotes: 5