.attr() vs .style()

in HTML you’ll see something like:

// .style("fill","red");
<text style="fill: red">

and

// .attr("fill","red");
<text fill="red">

Styles

use .style() for design stuff (e.g. colors, opacity, etc)

a good rule of thumb is, if it works in CSS, set it with .style()

Attributes

use .attr() for positioning/sizing details like x and y and height, width and radius