Reputation: 779
HTML Code:
<div>
<div>
<input id="chkA" type="checkbox" name="chkA">
</div>
<div>A</div>
<div id="A"></div>
</div>
Context is:
<div id="A"></div>
Problem:
I want to navigate to the first sibling of <div id="A"></div>
and check if it has a child of type input/checkbox.
Upvotes: 0
Views: 2095
Reputation: 69915
Try this
If you know the sibling is below the element
if($("#A").next().chldren(":checkbox").length){
//Yes I am a checkbox
}
Or if it is above
if($("#A").prev().chldren(":checkbox").length){
//Yes I am a checkbox
}
Or if you dont know
if($("#A").siblings(":first").chldren(":checkbox").length){
//Yes I am a checkbox
}
Upvotes: 1
Reputation: 32608
if( $("#A").siblings().first().children("input[type='checkbox']").length > 0) {
//code
}
Upvotes: 3