Link to home
Start Free TrialLog in
Avatar of HLRosenberger
HLRosenbergerFlag for United States of America

asked on

D3, mouseover, SVG, Javacript

I have SVG file.  Using D3 to load.  I want to change the fill color and/or the stroke width or color of a path on mouseover and mouseout.  I have the mouse event working, but I cant get the attributes/colors, etc, to change.  I can get the opacity to change. See code below .

                   sectionLayer.on('mouseover', function () {
                            d3.select(this).style("opacity", 0);

                            d3.select(this).style("stroke-width", 13);
                            d3.select(this).style("stroke", "blue");
                            d3.select(this).style("fill", "green");
                        });
Avatar of HLRosenberger
HLRosenberger
Flag of United States of America image

ASKER

Also, is there a way right in the SVG file to do a hover event, using CSS/classes?
Avatar of Theo Kouwenhoven
Hi HLRosenberg,

Please checkout Peter Collin's site about this, it explains a lot:
sectionLayer.on('mouseover', function () {
this.style.opacity = '0';
this.setAttribute("stroke-width", '13');
this.setAttribute("stroke", "blue");
this.setAttribute("fill", "green");
}); 

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of mccarl
mccarl
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Got it!   Thanks!
You're welcome!