如何使用JS为除特定图像之外的所有图像添加类

编程入门 行业动态 更新时间:2024-10-26 16:23:55
本文介绍了如何使用JS为除特定图像之外的所有图像添加类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

除了两个特定的图像外,我想为所有图像添加一个类.因为我不想将该类添加到徽标中.

I want to add a Class to all images except for two specific ones. Because i don't want to add that Class to the logo for example.

这就是我现在拥有的:

$('img').addClass('class_two');

我不想在其上添加此类的图像是:

The images where i don't want to add this class on are:

<img id="id_1" src="danielgotzlogo.png" alt="danielgotzlogo"> <img id="id_2" src="xxsbanner.jpg" alt="#">

但这会将其添加到所有图像.我如何不将班级添加到特定班级?

But this adds it to all images. How can i not add the Class to specific ones?

推荐答案

给出您不想影响的两个元素的特定ID:

Given the specific IDs of the two elements you don't want to affect:

$('img').not('#id1').not('#id2').addClass('myclass');

或:

$('img').not('#id1,#id2').addClass('myclass');

或:

$('img:not(#id1,#id2)').addClass('myclass');

更多推荐

如何使用JS为除特定图像之外的所有图像添加类

本文发布于:2023-10-31 19:17:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1547031.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   如何使用   JS

发布评论

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

>www.elefans.com

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