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
  • 4,009
  • 15
  • 45
  • 86

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
  • 6,147
  • 1
  • 21
  • 20