Reputation: 11791
All, Forgive me I am not professional of the jquery, I am stuck with figure out the selector as the title show . please help me thanks.
I have a function like this:
function (container)
{
var selectContentDiv= $("....",container);//I just don't know how to working with the selector context.
}
Supposed we the container
which contains the html structure like the below:
<div class="block-head">
<h3>test</h3>
</div>
<div class="block-content"><!--I want to get this one-->
<div class="block-head">
<h3>test</h3>
</div>
<div class="block-content">
....
</div>
</div>
I want to know how to get the direct first child which have the class named block-content
of the context? thanks.
Upvotes: 3
Views: 2616
Reputation: 27364
<div class="block-content"><!--I want to get this one-->
<div class="block-head">
<h3>test</h3>
</div>
<div class="block-content">
....
</div>
<div class="block-head">
<h3>test</h3>
</div>
</div>
from above HTML if you want to find direct child of block-content
$('.block-content > div.block-head')
EDIT according to Dream Eater Comment
Above code is added for example where .block-content
is the parent and div.block-head
is the child element.
So complete syntax would be.
$('parent > child')
Upvotes: 3
Reputation: 32750
Try this :
$(".block-head").next(".block-content")
This will give you the first .block-content
after .block-head
Upvotes: 0
Reputation: 50573
To get the first child of an element which has a .block-content class, use this:
$('div > .block-content');
I use a div as your parent element, which you didn't include in your html.
Upvotes: 3
Reputation: 5265
this will get you the first occurrence of a div element with class block-content
:
$('div.block-content').first()
Upvotes: 0