jQuery 从 Div 中删除所有类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16332478/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Remove All classes From Div
提问by anam
Is there any way to remove all classes from div ... on click of image. I want to remove all the classes from it.
有什么方法可以从 div 中删除所有类...单击图像。我想从中删除所有类。
Please Help,
请帮忙,
$(document).ready(function () {
$("img").click(function(){
var pos=$('img', this).attr('alt');
alert('i am imageFlip'+this.alt);
console.log('i am Image Flip');
var t = $(this);
t.prevAll().removeClass('lower').addClass('t1');
t.nextAll().removeClass('t1').addClass('t2');
});
});
Here in my code, I want to remove all classes from $(this)
.
在我的代码中,我想从$(this)
.
采纳答案by Zeb Rawnsley
You don't need to wrap this
in a jQuery selector to complete this job.
您不需要包装this
在 jQuery 选择器中来完成这项工作。
To remove all classes from the element
从元素中删除所有类
this.className = '';
回答by Andy
http://api.jquery.com/removeClass/
http://api.jquery.com/removeClass/
If a class name is included as a parameter, then only that class will be removed from the set of matched elements. If no class names are specified in the parameter, all classes will be removed.
如果类名作为参数包含在内,则只会从匹配的元素集中删除该类。如果参数中未指定类名,则将删除所有类。
回答by Irvin Dominin
You can use removeClasswithout using any class as a parameter.
您可以在不使用任何类作为参数的情况下使用removeClass。
Description: Remove a single class, multiple classes, or all classes from each element in the set of matched elements.
描述:从匹配元素集中的每个元素中删除单个类、多个类或所有类。
Like:
喜欢:
$(this).removeClass();
回答by Dinesh Chauhan
You can use .attr('class','')
to remove all classes from any element.
您可以使用.attr('class','')
从任何元素中删除所有类。
Example:
例子:
$(this).attr('class','')
回答by Abhijit
You can use removeClass()
to remove all the classes at one shot.
您可以使用一次removeClass()
删除所有类。
For example, there is a div
with id = "myDiv". You want to remove all the classes that this div
has, then you can use the below statement:
例如,有一个div
with id = "myDiv"。你想删除所有的类div
,那么你可以使用下面的语句:
$("#myDiv").removeClass();
回答by Priyangna
You can use .removeAttr( "class" )
to remove all classes from element.
您可以使用.removeAttr( "class" )
从元素中删除所有类。
Example:
例子:
$(this).removeAttr( "class" )
回答by Nikhil Gyan
$(this).removeClass();
Using removeClass
with no parameters will remove all of the selector's classes
removeClass
不带参数使用将删除所有选择器的类