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><textid="zero"x="0"y="0">0</text><textid="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"?"