PLui PLui - 1 year ago 100
Javascript Question

D3 transition not working

I have the following SVG element:

<svg id='svgTest' xmlns="" version="1.1">
<g id="test">
<rect height="20" width="50" fill="blue"/>

I want to add a transition for the blue rectangle. I tried with the following code with D3:

var rect ="#test");

But it doesn't seem to do anything. What's wrong?

Answer Source

You need to select the 'rect' element. Try this:

var rect ="#test rect");


If you want to update multiple elements, use d3.selectAll().