Created
May 6, 2017 08:50
-
-
Save egorvinogradov/d6d72870dc1caf972b7dc14b8b02a7a8 to your computer and use it in GitHub Desktop.
Get SVG element's outerHTML
This file contains 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
// Usage: | |
// getSVGOuterHTML('.icon-preview__svg svg'); | |
function getSVGOuterHTML(selector){ | |
var icon = document.querySelector(selector); | |
var attrs = Array.prototype.map.call(icon.attributes, function(attr){ | |
return attr.name + '="' + attr.value + '"'; | |
}).join(' '); | |
return '<svg ' + attrs + '>' + icon.innerHTML + '</svg>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment