Assume I have a large string that contains raw svg xml, and I want to change each instance of <path to <path class="pathX" (where X is the index of the matched item). What's the best way to do this in javascript? I'm using this code, which works, but I'm curious if there's a better way:
var svgArray = mySvgStr.split('<path ');
for(var i = 1, len = svgArray.length; i < len; i++) {
var newStr = 'class="path' + i + '" ' + svgArray[i];
svgArray[i] = newStr;
}
var svgWithClasses = svgArray.join('<path ');
XmlDOMto parse and add theattribute