meWantToLearn
meWantToLearn

Reputation: 1700

jquery hide 2 div in entire page

I want to hide all 2nd div inside another div

     <div class="inner">
       <div class="content"></div>
       **<div class="content"></div>**   // this show get hidden
    </div>

     <div class="inner">
       <div class="content"></div>
       **<div class="content"></div**>   // this should get hidden
    </div>

I have tried this:

           $($('.inner').children()[12]).hide();

but it only hides one element,

Upvotes: 0

Views: 105

Answers (4)

defau1t
defau1t

Reputation: 10619

$(".content").next().hide(); will do the Job.

OR

$(".inner").find(".content").eq(1).hide();

Upvotes: 0

Musa
Musa

Reputation: 97707

Try

$('.inner div:nth-child(2)').hide()

http://jsfiddle.net/TmWzd/

Upvotes: 0

Shawn Steward
Shawn Steward

Reputation: 6825

You can use the nth-child selector from jQuery to easily accomplish this.

$(".inner div:nth-child(2)").hide();

Upvotes: 0

user1796666
user1796666

Reputation:

If you want to do it without :nthchild selector:

$('.inner').each(function()
{
   $(this).find('.content').eq(1).hide(); 
});​

with :nthchild:

$(".inner div:nth-child(2)").hide();

Upvotes: 1

Related Questions