I'm a bit stuck here. I'm trying to show the first div for each section I have using jQuery. There's multiple parent elements .each-business-content-extra
which has a few child elements .each
. Each .each
is set to display none via the CMS, but I want the first .each
in each .each-business-content-extra
that exists to be set to display:block.
I tried this —
$('.each-business-content-extra .each:first').each(function() {
$(this).show();
});
Any ideas?
Thanks, R
You can use .eq() to target the first element of each .each class. http://api.jquery.com/eq/
Try this:
$('.each-business-content-extra .each:eq(0)').each(function() {
$(this).show();
});
Alternatively, try this:
$('.each-business-content-extra .each:eq(0)').css('display', 'block');
尝试这个:
$('.each-business-content-extra').children(":first").show();
You can do it your way, but the correct selector is :first-of-type
:
$('.each-business-content-extra .each:first-of-type').each(function() {
$(this).show();
});
您可以尝试这个简单的方法,
$('.each-business-content-extra .each:first-child').show();
Turns out it was a combination of everyones...
$('.each-business-content-extra').each(function() {
$(this).find('.each:first').show();
});
Thanks so much.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.