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)
.
To remove all classes, use the removeClass() method with no parameters. This will remove all of the item's classes.
Use the classList. remove() method to remove a class from a div element, e.g. box. classList. remove('my-class') .
To remove all CSS classes of an element, we use removeClass() method. The removeClass() method is used to remove one or more class names from the selected element.
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.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With