Remove All classes From Div
Is there any way to remove all classes from div ... on click of image. I want to remove all the classes from it.
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)
.
Solution 1:
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.
Solution 2:
You can use removeClass without using any class as a parameter.
Description: Remove a single class, multiple classes, or all classes from each element in the set of matched elements.
Like:
$(this).removeClass();
Solution 3:
You don't need to wrap this
in a jQuery selector to complete this job.
To remove all classes from the element
this.className = '';