parentNode in d3 svg

时间:2016-04-04 16:30:36

标签: javascript d3.js svg parent

I've used an example snippet, cited here, to get to the parent node of a svg element, but I obtain undefined. Why? And How to correct it?

var svg = d3.select('svg');

var lbl=    svg.append("text")
        .attr("x", 10)
        .attr("y", 110)
        .text("aaaaa");

alert(lbl.parentNode);  

(JSFiddle version here)

1 个答案:

答案 0 :(得分:1)

lbl is still a d3 selection, to do .parentNode you need to get the DOM node for lbl first

alert(lbl.node().parentNode);