[英]How to ignore child DIV if parent div has some specific class
How can I ignore the class extra
for child div with class child2
?如何忽略 class
child2
child div 的extra
类?
<div class="parent extra">
<div class="child1">
Some text
</div>
<div class="child2">
Some text
</div>
</div>
The extra
class is used for translating the texts inside divs
,but I don't want to translate the child div
with class child2
. extra
类用于翻译divs
内的文本,但我不想用类child2
翻译child div
。 How can I filter this?我怎样才能过滤这个?
The 'extra' class is used for translating the texts inside divs,but I don't want to translate the child div with class 'child2'.How can I filter this?
'extra' 类用于翻译 div 中的文本,但我不想用类 'child2' 翻译子 div。我该如何过滤?
$('.extra :not(.child2)')
This selector is saying这个选择器说
extra
extra
抓取所有元素child2
child2
类的直接/嵌套孩子You can :你可以 :
loop all div with parent class --> $( ".parent" ).each()
使用父类循环所有 div -->
$( ".parent" ).each()
check if the current class has a class extra --> if($(this).hasClass( "extra" ){}
检查当前类是否有一个额外的类 -->
if($(this).hasClass( "extra" ){}
if the current parent class has a class extra loop all children and check if it has a child with class : child2 $(this).children().each()
and if($(this).hasClass( "child2" )){}
如果当前的父类有一个额外的类循环所有子类并检查它是否有一个类的子类:
if($(this).hasClass( "child2" )){}
$(this).children().each()
和if($(this).hasClass( "child2" )){}
If it is the case get the parent and do some process...如果是这种情况,请获取父母并进行一些处理...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.