开发者

Check if the sibling of an element has a child that is a checkbox in jquery

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>

Pr开发者_如何学JAVAoblem:

I want to navigate to the first sibling of <div id="A"></div> and check if it has a child of type input/checkbox.


 if( $("#A").siblings().first().children("input[type='checkbox']").length > 0) {
    //code
 }


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
}


if($('#A').prevAll().has(':checkbox').length>0) {
//code
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜