0

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)

tic
  • 3,599
  • 15
  • 39
  • 82

1 Answers1

1

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

alert(lbl.node().parentNode);
mgraham
  • 5,867
  • 1
  • 18
  • 19