Last active
August 29, 2015 14:16
-
-
Save lfarroco/0047cd96348c9801a195 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Extract SVG: three lines of JavaScript that allow you to extract the contents | |
//of a SVG <object> tag into your DOM | |
//After the extraction you are able to select the inner elements of the SVG with CSS and JS | |
//It replaces the original <object> tag with its raw SVG | |
//el: a DOM element | |
//eg. el = document.querySelector('#elementId') | |
//extractSvg(el) | |
//You might also place an onload attribute in your object to force its extraction when possible | |
//<object data="test.svg" type="image/svg+xml" onload="extractSvg(this)"></object> | |
function extractSvg(el) { | |
var svg = el.contentDocument; | |
svg = svg.documentElement; | |
el.parentNode.replaceChild(svg,el); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment