简体   繁体   中英

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 )

lbl仍然是d3选择,要执行.parentNode,您需要首先获取lbl的DOM节点

alert(lbl.node().parentNode);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM