[英]Show each first element in a list of parent elements (jQuery+CSS)
我有点卡在这里。 我试图显示我使用jQuery的每个部分的第一个div。 有多个父元素.each-business-content-extra
,其中有一些子元素.each
。 每个.each
均设置为通过CMS不显示任何内容,但我希望将每个.each-business-content-extra
中的第一个.each
设置为display:block。
我试过了
$('.each-business-content-extra .each:first').each(function() {
$(this).show();
});
有任何想法吗?
谢谢,R
您可以使用.eq()定位每个.each类的第一个元素。 http://api.jquery.com/eq/
尝试这个:
$('.each-business-content-extra .each:eq(0)').each(function() {
$(this).show();
});
或者,尝试以下操作:
$('.each-business-content-extra .each:eq(0)').css('display', 'block');
尝试这个:
$('.each-business-content-extra').children(":first").show();
您可以按照自己的方式做,但是正确的选择器是:first-of-type
:
$('.each-business-content-extra .each:first-of-type').each(function() {
$(this).show();
});
您可以尝试这个简单的方法,
$('.each-business-content-extra .each:first-child').show();
原来这是每个人的结合...
$('.each-business-content-extra').each(function() {
$(this).find('.each:first').show();
});
非常感谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.