[英]How To remove Parent class base of child class by Prototype or jquery
I want to remove class on base of child class in html content.我想根据 html 内容中的子类删除类。
<div class="mydds">
<dt><label class="required"><em>*</em>Light Source</label></dt>
<dd class="last">
<div class="input-box">
<select style="width:230px;" name="super_attribute[224]" id="attribute224" class="required-entry super-attribute-select remArro" onchange="return changeSku(224, this);" disabled="">
<option value="226" data-label="led retrofit/fluo">LED Retrofit/Fluo</option>
</select>
</div>
</dd>
</div>
In this code in select you can see a class remArro, and in <dt><label class="required">
.在 select 中的这段代码中,您可以看到一个类 remArro,在
<dt><label class="required">
。 I want to remove required class on base of remArro class, is it possible?我想在 remArro 类的基础上删除所需的类,这可能吗?
$('.remArro').parents('.mydds').find('label').removeClass('required')
那是你想要的吗?
You can use $.closest()
in jQuery to find an ancestor with a specific selector.您可以在 jQuery 中使用
$.closest()
来查找具有特定选择器的祖先。 You'll need to get the closest common parent then find your target, since label.required
is not the parent of the .remArro
element.您需要获得最近的公共父元素,然后找到目标,因为
label.required
不是.remArro
元素的父元素。
$('.remArro').closest('.mydds').find('label').removeClass('.required')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.