I am currently working on creating a custom plugin for SVGO that will batch clean and format SVG files exported from Illustrator.
My main objective is to group elements with similar attributes by assigning them a common class, instead of having separate classes for each individual element.
Everything seems to be functioning well, except for when I attempt to remove the classes from the elements. At that point, the loop seems to lose its tracking ability, and I am struggling to identify the cause of this issue.
If anyone has any insights or suggestions on how to resolve this problem, I would greatly appreciate it!
Below is an excerpt from the section of my code where the issue arises:
// Prior to this, looping through elements with conditions to preserve <g></g> as "g"
var myclass;
g.content.forEach(function(inner){
if (inner.hasAttr("class")){
myclass = inner.attr('class').value; // This line functions correctly
inner.removeAttr('class'); // Removing the class causes issues even though it's called after (myclass = "")
}
});
g.addAttr({
name: 'class',
value: myclass,
prefix: '',
local: ''
});