I already know the following code works. But I don't know the way to access the animation from JavaScript. I want to create lines and animations dynamically using JavaScript. How to do this?
<!DOCTYPE html>
<html>
<head>
<title>title</title>
</head>
<svg width="500" height="500">
<line x1="100" y1="100" y2="300" stroke="black">
<animate attributeName="y1" from="100" to="300" dur="2s" fill="freeze"/>
<animate attributeName="x2" from="100" to="300" dur="2s" fill="freeze"/>
</line>
</svg>
</body>
</html>
That is, I want to do the same thing as the above code using JavaScript. The format is like this.
<!DOCTYPE html>
<html>
<head>
<title>title</title>
</head>
<svg id="myCanvas" width="500" height="500">
</svg>
<script>
// do something
</script>
</body>
</html>