tic
tic

Reputation: 4189

parentNode in d3 svg

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)

Upvotes: 0

Views: 1858

Answers (1)

mgraham
mgraham

Reputation: 6207

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

alert(lbl.node().parentNode);

Upvotes: 1

Related Questions