Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide third child div in jquery

I am trying to hide third child div in jQuery , but its hide first child div subchild.

I am trying with below code :-

Html :-

<div id="parent-1">
    <div id="child-1" class="child">CHILD 1
       <div id="sub-child-1" class="subchild">SUB CHILD 1</div>
       <div id="sub-child-2" class="subchild">SUB CHILD 2</div>
       <div id="sub-child-3" class="subchild">SUB CHILD 3</div>
    </div>
    <div id="child-2" class="child">CHILD 2</div>
    <div id="child-3" class="child">CHILD 3</div>
</div>

Jquery :-

$(document).ready(function () {
   $('div#parent-1 div:eq(2)').css("display", "none");
});

I need to hide child-3 here. but it is hiding sub-child-3.

here is jsfiddle

Any suggestion??

Thanks in advance.

like image 430
Roopendra Avatar asked Feb 16 '23 12:02

Roopendra


1 Answers

$(document).ready(function () {
   $('div#parent-1 > div:eq(2)').css("display", "none");
});

The > does it all.

like image 114
JNDPNT Avatar answered Feb 19 '23 03:02

JNDPNT