d3.js

style method does not take object  #angularjs #reactjs

  • I am trying to change CSS properties of all div elements where class=item (by accessing the div elements using D3 selectAll()).
  • Stack Overflow works best with JavaScript enabled
  • I am able to change only single property using style() but when I try to pass object to style() nothing happens.
  • If you want to set multiple style properties, you need to use multiple style() functions

I am trying to change CSS properties of all div elements where class=item (by accessing the div elements using D3 selectAll()). I am able to change only single property using style() but when I try to pass object to style() nothing happens.
For example this works fine:

@ng_real_ninja: style method does not take object #angularjs #reactjs

I am trying to change CSS properties of all div elements where class=item (by accessing the div elements using D3 selectAll()). I am able to change only single property using style() but when I try to pass object to style() nothing happens. For example this works fine:

But, this doesn’t:

I read somewhere that styles() must be used instead of style() when passing an object but even styles() does not work. Here is the codepen link containing the code : http://codepen.io/anon/pen/JEoXOV

Can someone tell me what I am missing out here ?

For the sake of parsimony, the multi-value methods—where you pass an object to set multiple attributes, styles or properties simultaneously—have been extracted to d3-selection-multi and are no longer part of the default bundle. The multi-value map methods have also been renamed to plural form to reduce overload: selection.attrs, selection.styles and selection.properties.

d3.js