Bhumi Shah
Bhumi Shah

Reputation: 9476

How to hide all divs in jquery of particular div?

I have HTML like below

<div  id="L0" >
    <div id="P0">
      //code
    </div>
    <div id="P1">
         //code
    </div>
    <div id="p2">
           //code
    </div>
</div>
<div  id="L1" >
    <div id="P0">
      //code
    </div>
    <div id="P1">
         //code
    </div>
    <div id="p2">
           //code
    </div>
</div>

So I want to hide all inner P divs of particular L. I have tried below code but it is not working.

$('#L0 div[id^=P]').hide();

Upvotes: 0

Views: 237

Answers (5)

Arlind Hajredinaj
Arlind Hajredinaj

Reputation: 8519

Add a class to your top level DIV's for example:

<div id="L0" class="top-div">
    <div id="P0">1</div>
    <div id="P1">2</div>
    <div id="p2">3</div>
</div>
<div id="L1" class="top-div">
    <div id="P0">4</div>
    <div id="P1">5</div>
    <div id="p2">6</div>
</div>

Now you can easily select all DIV's with the class top-div and hide their children, In this case the inner divs:

$('div.top-div').children().hide();

If you want to hide the inner divs of only one outer (L) div use the code below:

$('div#L0').children().hide();// for your first div L0
$('div#L1').children().hide();// for your second div L1

Upvotes: 0

Akshay
Akshay

Reputation: 14348

This worked for me. Two of them are not hiding because they are small letter p

$('div[id^="P"]').hide();
$('div[id^="p"]').hide();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div  id="L0" >
    <div id="P0">
      //code
    </div>
    <div id="P1">
         //code
    </div>
    <div id="p2">
           //code
    </div>
</div>
<div  id="L1" >
    <div id="P0">
      //code
    </div>
    <div id="P1">
         //code
    </div>
    <div id="p2">
           //code
    </div>
</div>

Upvotes: 0

anand kulkarni
anand kulkarni

Reputation: 156

just hide your L0 div and all inner P will hide automatically for particular Div try following code

$('#L0').hide();

Upvotes: 0

Girish
Girish

Reputation: 12117

Last div id p is small char and in selector used CAPITAL P char

<div id="p2">

change

<div id="P2">

Upvotes: 0

David Slav&#237;k
David Slav&#237;k

Reputation: 1192

$('#L0 div[id^=P], #L0 div[id^=p]').hide();

Upvotes: 1

Related Questions