You can manipulate SVG using JavaScript, but it will also respond to CSS changes.
If you have an SVG with mysvg and path with id myborder , you can define a style for the border path:
#mysvg #myborder { stroke: orange; }
You can directly manipulate SVG or define styles as usual. The simplest thing is to manipulate the wrapper div . This is because manipulating HTML styles is simpler than SVG and works better with standard JS and JS libraries:
<div id="myshape"> <svg id="mysvg" height="600" width="400"> <path id="myborder" d="..." stroke="blue" stroke-width="5"> </svg> <div id="content">Content</div> </div>
Then you can have the following classes:
#myshape #mysvg #myborder { stroke: blue; } #myshape.hilite #mysvg #myborder { stroke: orange; }
A simple change to the parent class will update your SVG. Add / remove the hilite class hilite parent div in this case to change the border color.
Example: http://jsfiddle.net/jtbowden/ssrker2h/2/
JS is not required to change, but I use it to change the class. This could be easily done using the hover attribute, etc.
Example CSS only:
#content { padding: 50px; position: absolute; top: 25px; left: 25px; font-size: 42px; font-family: Arial; font-weight: bold; } #myshape:hover #myborder { stroke: orange; }
<div id="myshape"> <svg id="shape" height="600" width="420"> <defs> <pattern id="mybackgnd" patternUnits="userSpaceOnUse" width="400" height="590"> <image xlink:href="http://placekitten.com/g/400/590" x="0" y="0" width="400" height="590" opacity="0.5" /> </pattern> </defs> <path id="myborder" d="M 20 60 l 40 -40 l 320 0 c 10 0 20 10 20 20 l 0 500 c 0 10 -10 20 -20 20 l -340 0 c -10 0 -20 -10 -20 -20 z" stroke="blue" stroke-width="5" fill="url(#mybackgnd)" />Sorry, your browser does not support inline SVG.</svg> <div id="content">Hover Me</div> </div>
source share