Good day! When searching for the greatest height of the path elements in svg for some reason, the height is zero. I do not understand what could be the case, perhaps the object does not have time to load ... Any idea why this is so?
<object id="graph" name="graph" type="image/svg+xml" data="data:image/svg+xml;base64,..."></object> <script> var a = document.getElementById("graph"); a.addEventListener("load",function() { var svgDoc = a.contentDocument; var path = svgDoc.getElementsByTagName('path'); var maxHeight = 0; $(path).each(function (i) { var rect = path[i].getBoundingClientRect(); if (rect.height > maxHeight) { maxHeight = rect.height; } }); $("#graph").height(maxHeight ); console.log(maxHeight); // 0 }, false); </script>