Jquery plugin to Swap Images with svg src with inline svg Elements.
If you've ever used svg icons, you would have added it as an source, like so.
<img src="circle.svg" />
this takes away all the editability of the svg. you cannot use css selectors, etc.
the plugin swaps this
<img class="swap-svg" id="myid" src="circle.svg" />
<svg class="swap-svg" id="myid" xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" preserveAspectRatio="none" x="0px" y="0px" width="330px" height="400px" viewBox="0 0 330 400">
......
</svg>
now you can use your css selector to change colors, etc.
- Add the scripts.
<script src="bower_components/jquery/dist/jquery.min.js" charset="utf-8"></script>
<script src="swap-svg.js" charset="utf-8"></script>
- Add a class to the images you wanna swap
<img class="swap-svg" id="myid" src="circle.svg" />
<swap class="swap-svg" src="BatmanHat.svg"></swap>
yes, it works on any tag as long as it as a src attribute with svg file source.
- initiate the plugin.
$('img.swap-svg').swapSvg();
its important that you select a image tag with a class of swap-svg