Manipulate SVG viewbox with JavaScript (no libraries)

It would be good to see the context of the svg, but the following worked for me with a pure SVG document:

shape = document.getElementsByTagName("svg")[0];
shape.setAttribute("viewBox", "-250 -250 500 750"); 

Maybe it's because viewBox is case-sensitive?


You have an error in your code: "viewbox" is different than "viewBox"...B is in uppercase. Change the code to:

a.setAttribute("viewBox","0 0 " + SVGWidth + " 300");