snap.svg - How to preserve spaces in svg text -
to preserve spaces in textelement of svg, 1 should use 'xml:space="preserve"' attribute of text (jsfiddle). however, isn't working. doing wrong?
// init snap var svgelement=document.getelementbyid("mainsvgid"); var s = snap(svgelement).attr({height: 300, width: 300}); // greate group rectanle var parentgroup=s.g().attr({id: "parent"}); var rect1 = s.rect(0, 0, 200, 200).attr({fill: "#bada55"}); parentgroup.add(rect1); // add text preserve attribute var text = s.text(0, 20, " text1 text2"); text.node.setattribute("xml:space", "preserve"); parentgroup.add(text);
you're there. need create attribute in xml namespace need setattributens rather setattribute
text.node.setattributens("http://www.w3.org/xml/1998/namespace", "xml:space", "preserve");
Comments
Post a Comment