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)
答案 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);