2014-10-10 78 views
0

我在body下创建一个svg元素。随后我将更多的东西添加到svg。D3:如何选择svg元素下的所有东西

svg = d3.select("body") 
    .append("svg") 
    .attr("width", 1000) 
    .attr("height", 500) 

svg.append("g") 
// ... and many others more 

如何选择svg下的所有东西,但svg本身?像,

d3.select(all_under("svg")) 
+1

你为什么不使用类,并把它添加到元素(例如:.attr( '类',“myClass的')),你想选择,然后使用类选择,如:d3.selectAll('。myClass') – slotomo 2014-10-10 21:15:26

回答

2
d3.select('svg').selectAll('*') 

,甚至更好,因为Lars Kotthoff旨意。

d3.selectAll("svg > *") 
+2

甚至'd3.selectAll(“svg> *”)'。 – 2014-10-10 21:36:45