Why javascript does not change svg width attribute to 300? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Why javascript does not change svg width attribute to 300?

<!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <svg width="30" height="500"> <circle cy="60" cx="60" r="50" > </circle> </svg> <script> var el = document.getElementsByTagName("svg"); el[0].width ="300"; </script> </body> </html>

11th Feb 2018, 5:26 PM
Pero 5ar
Pero 5ar - avatar
3 Answers
+ 5
try width = 300 + "px"
11th Feb 2018, 7:13 PM
Олег Самсонов
Олег Самсонов - avatar
+ 4
How i can make moving (changing cx an cy)?
12th Feb 2018, 12:42 PM
Pero 5ar
Pero 5ar - avatar
+ 2
(This may not work, this is only my idea on it. I apologize if this isn’t correct). The width is already assigned in <svg width=“30” height=“500”>. If you want to change it, just change the width in the SVG tag.
11th Feb 2018, 5:42 PM
luciel
luciel - avatar