从活动div中删除子类[重复](Remove child class from active div [duplicate])

编程入门 行业动态 更新时间:2024-10-26 06:30:28
从活动div中删除子类[重复](Remove child class from active div [duplicate])

这个问题在这里已有答案:

如何在jQuery中选择具有多个类的元素? 11个答案

我有一个问题是只从活动div中删除img类:

<div class="thumb thumb-selected"> <img class="img-thumb BWFilter BWfade" src="100x100.jpg" alt=""><img crossorigin="anonymous" style="height: 100px; width: 100px; margin-top: 0px; margin-left: 0px;" class="img-thumb" src="3-100x100.jpg" alt=""></div>

我想删除(BWFilter BWfade)类,只为这个div(.thumb .thumb-selected),我正在尝试使用这个jquery代码:

$('.thumb .thumb-selected').find('.img-thumb img').removeClass("BWFilter BWfade");

This question already has an answer here:

How can I select an element with multiple classes in jQuery? 11 answers

I have a problem to remove only img class from active div :

<div class="thumb thumb-selected"> <img class="img-thumb BWFilter BWfade" src="100x100.jpg" alt=""><img crossorigin="anonymous" style="height: 100px; width: 100px; margin-top: 0px; margin-left: 0px;" class="img-thumb" src="3-100x100.jpg" alt=""></div>

I want to remove (BWFilter BWfade) class, only for this div (.thumb .thumb-selected), I'm trying with this jquery code:

$('.thumb .thumb-selected').find('.img-thumb img').removeClass("BWFilter BWfade");

最满意答案

removeClass接受多个要删除的类:

$('.thumb.thumb-selected > img.img-thumb').removeClass('BWFilter BWfade');

> - 选择器仅在img是div的直接子项时才匹配。

参考

.removeClass()

css - 子选择器

the removeClass accepts more then one class to remove:

$('.thumb.thumb-selected > img.img-thumb').removeClass('BWFilter BWfade');

The > - selector will only match when the img is a direct child of your div.

Reference

.removeClass()

css - child-selector

更多推荐

本文发布于:2023-08-05 08:10:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1428778.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:子类   Remove   div   child   duplicate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!