user1855009
user1855009

Reputation: 971

Switching "d" value in svg path using javascript?

I'm trying to switch out the "d" value and replace it with a dynamically generated number, but I keep getting "unexpected number" as my output. Here's what I currently have:

<path id="pathA" d="M 0 0 l 0 255" stroke="none" stroke-width="0" fill="none"/>

<script>
var sink = document.getElementById("pathA");
sink.setAttribute("d", M 0 0 l 0 (round*25.5));
</script>

Upvotes: 1

Views: 599

Answers (1)

Nick
Nick

Reputation: 6025

Your script as presented has two problems.

First, The second argument you're passing to the setAttribute is not correct. Try:

sink.setAttribute("d", "M 0 0 1 0 " + (round * 25.5));

Second, you don't provide a value for round at any point.

Upvotes: 1

Related Questions