I have an SVG of baseball diamond, and I'm trying to set its width and height via the attributes of its parent container.
Here's my fiddle: https://jsfiddle.net/a5mz90jy/6/
Here's my Javascript:
const svgBaseballField = document.getElementById('diamond');
console.log(svgBaseballField);
const svgContainer = document.getElementsByClassName('svg_container');
console.log(svgContainer);
const svgContainerHeight = svgContainer.clientHeight;
console.log(svgContainerHeight);
const svgContainerWidth = svgContainer.clientWidth;
svgBaseballField.setAttribute("width", svgContainerWidth);
svgBaseballField.setAttribute("height", svgContainerHeight);
svgBaseballField.setAttribute("viewBox", "0 0 100 100");
I know something is wrong, because svgContainerHeight and svgContainerWidth are undefined. I also know I need to set the viewport to something.
I also checked this before: How can I make an svg scale with its parent container?