I found both of them works in my test:
.on("mouseover", function() { d3.select(this) .select("text") .style("fill","red"); })
or
.on("mouseover", function() { d3.select(this) .select("text") .attr("fill","red"); })
attr() function is used to set the attribute of the element that is selected. The name of the attribute and value of the attributes are to be set using this function.
d3. select selects the first matching element whilst d3. selectAll selects all matching elements. Both functions take a string as its only argument.
For example, d3. select returns a selection with one group containing the selected element: var selection = d3. select("body");
If you look at the HTML you get, you'll see something like:
<text style="fill: red">...
and
<text fill="red">...
..which are both legal in SVG, but using attr when you need style could trip you up if you use it for something else.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With