简体   繁体   中英

d3js selectAll elements by its CSS style?

Is there a way to select all circle with style visibility===visible ? Something like this: svg.selectAll("circle").filter(function(d) { return this.style.visibility === 'visible'; })

You can use d3.selectAll to select all circle svgs ( https://github.com/mbostock/d3/wiki/Selections#d3_selectAll ).

This is going to return a 2 dimensional array. It's essentially an array containing arrays of what you selected. Assuming you have 25 circles:

circs = d3.selectAll("circle") // here circs may be [Array[25]]
circs = circs[0] //now circs is an array of circles

Now all you need to do is filter based on the computed style for that element. Check out this answer for how you'd do that :)

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