Example of getBBox()
CSS
svg {
background-color: linen;
}
JavaScript
var svg = d3.select("body").append("svg").attr('width',600).attr('height',100);
var text = svg.append("text")
.attr("x",10)
.attr("y",20)
.text("hello there from Nivaldo who is current living in Va Beach");
var rect = svg.append("rect")
.attr(text.node().getBBox())
.style("fill","red")
.style("opacity",0.5);
console.log(text.node().getBBox());