I have a simple problem, but for some reason I can't figure out the
jQuery way to do it. Basically, all I want is to target every child
(except the first one) of a group of elements.
Say, for example, one has multiple divs:
<div class="myDiv">
First
Second
Third
</div>
<div class="myDiv">
First
Second
Third
</div>
And say, I want to hide every except the first one of every <div>:
<div class="myDiv">
First
</div>
<div class="myDiv">
First
</div>
I thought I could simply:
$('div.myDiv p').not(':first').hide();
But that only acts on the first <div> and not all of them resulting
in:
<div class="myDiv">
First
</div>
<div class="myDiv">
First
Second
Third
</div>
So I thought I have to act on each <div>:
$('div.myDiv').each(function(){
$('p').not(':first').hide();
})
But that only acts on the first div as well. I know it's something
fundamental I missing, but for the life of me can't see it...