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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -