Skip to content Skip to sidebar Skip to footer

SVG GetAttribute/setAttribute Simply Adding To Coordinates Instead Of "setting"?

Solution 1:

There are a couple of issues here.

Firstly zero and one have no attributes to begin with so getAttribute will return null. Changing your markup to this will fix it

<defs>
    <text id="zero" x="0" y="0">0</text>
    <text id="one" x="0" y="0">1</text>
</defs>

Secondly getAttribute returns a string so you need to use parseFloat to get a number out of it e.g.

var y = parseFloat(e.getAttribute("y"));
var x = parseFloat(e.getAttribute("x"));

Making these two changes seems to make it do what you want


Post a Comment for "SVG GetAttribute/setAttribute Simply Adding To Coordinates Instead Of "setting"?"