+ 1

Line and variable

Can I use this in HTML and Javascript? <svg> <line x1="var:a" x2="var:b"/> </svg> <script> var a = 10 var b = 100 </script>

17th Oct 2018, 1:49 PM
Samuel STEF
Samuel STEF - avatar
1 Answer
+ 11
You can. Like this: <svg></svg> <script> var newLine = document.createElementNS('http://www.w3.org/2000/svg','line'); newLine.setAttribute('x1','0'); newLine.setAttribute('y1','0'); newLine.setAttribute('x2','200'); newLine.setAttribute('y2','200'); newLine.setAttribute("stroke", "black") document.querySelector("svg").append(newLine); </script>
17th Oct 2018, 5:28 PM
Igor Makarsky
Igor Makarsky - avatar