本文介绍了如何使用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为除特定图像之外的所有图像添加类
发布评论