Reputation: 5448
I have the following markup:
<div class="form-fields">
<div class="row">
<span class="info">Info</span>
</div>
</div>
Using the children selector how can I select span.info? I have tried doing:
$('.form-fields').children('.row .info')
But this didn't work for me.
EDIT: Thanks for the answers everyone. If I assign the container DIV as follows:
var parentDiv = $('.form-fields')
Then using the var 'parentDiv' what is the best way to select span.info?
Upvotes: 4
Views: 5808
Reputation: 3183
$('.form-fields').children('.row').children('.info')
you can test it like:
$(document).ready(function() {
alert( $('.form-fields').children('.row').children('.info').length);
});
Upvotes: 0
Reputation: 236022
.children()
will only grab immediate
child nodes. You need to invoke .find()
.
$('.form-fields').find('.row .info')
or even
$('.form-fields').find('.row').find('.info');
just by selector
$('.form-fields .info')
Reference: .children(), .find()
Upvotes: 2
Reputation: 237865
Use find
to get non-direct descendants:
$('.form-fields').find('.row .info')
Upvotes: 9
Reputation: 319601
Why do you need to use .children
?
$('.form-fields span.info')
Upvotes: 2