Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get class of selected svg element in d3

Tags:

d3.js

How do i use instance of <rect> of a svg to get it's class?

I have to remove lines which have same class as the clicked <rect>.

I tried using selection.class() which obviously didn't work nor did selection.classed() help.

like image 366
vjdhama Avatar asked Aug 12 '14 17:08

vjdhama


People also ask

What do the select () and selectAll () functions in d3 do?

select selects the first matching element whilst d3. selectAll selects all matching elements. Both functions take a string as its only argument. The string specifies which elements to select and is in the form of a CSS selector string (e.g. div.

Can we group SVG elements in d3js?

The <g> SVG element is a container used to group other SVG elements. Transformations applied to the <g> element are performed on its child elements, and its attributes are inherited by its children. We can create a group element with D3. js by appending a g element using any selection.

What type does d3 Select Return?

The d3. js is used to select the first element that matches the specified selector string. If any element is not matched then it returns the empty selection. If multiple elements are matched with the selector then only the first matching element will be selected.

What is G in d3js?

It appends a 'g' element to the SVG. g element is used to group SVG shapes together, so no it's not d3 specific.


1 Answers

when using d3 I have found this works

selection.attr("class");
like image 98
Camron_Godbout Avatar answered Oct 19 '22 03:10

Camron_Godbout