score:20

Accepted answer

myrect is a d3 selection and not an html element.

try this code:

myrect.node().getbbox();

var svgcontainer = d3.select("svg");  

var myrect = svgcontainer.append("text")
                .attr("x", 10)
                .attr("y", 20)
                .text("lorem ipsum")
                .attr("font-weight", "bold")
                .attr("fill", "white");

console.log("getbbox = ", myrect.node().getbbox());
svg{
  background: green;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
<svg width="500" height="800"></svg>


Related Query