Remove all classes from SVG using jquery Remove all classes from SVG using jquery jquery jquery

Remove all classes from SVG using jquery


You can't call .removeClass() on a SVG, unfortunately.

Use .attr() instead.

$('.someClass').attr('class','');

additional sources:

Martin Wolf

Similar SO Question


This ( $('.someClass').attr('class',''); ) will delete all the classes of all elements with class someClass.


This should do the trick ( retains other classes):

$(".someClass").each(function(){     var classes = $(this).attr("class").split(" ");     var otherClasses = "";     for(var i = 0; i<classes.length; ++i){        if(classes[i] !== "someClass"){            otherClasses += classes[i] + " ";        }     }     $(this).attr("class",otherClasses);});

Thanks @xehpuk for his comments.


You can use removeAttr, which will find all the matched elements and will remove the given attribute.
In your case this code will find all elements with class someClass and will remove the attribute class.
And the good in this code is that it will not leave an empty attribute.

$('.someClass').removeAttr( "class" );