Skip to content

Instantly share code, notes, and snippets.

@egorvinogradov
Created May 6, 2017 08:50
Show Gist options
  • Save egorvinogradov/d6d72870dc1caf972b7dc14b8b02a7a8 to your computer and use it in GitHub Desktop.
Save egorvinogradov/d6d72870dc1caf972b7dc14b8b02a7a8 to your computer and use it in GitHub Desktop.
Get SVG element's outerHTML
// 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