Skip to content

Instantly share code, notes, and snippets.

@gka
Forked from jarek-foksa/gist:2648095
Created September 7, 2012 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gka/3666005 to your computer and use it in GitHub Desktop.
Save gka/3666005 to your computer and use it in GitHub Desktop.
SVGElement.prototype.innerSVG shim
Object.defineProperty(SVGElement.prototype, 'innerSVG', {
get: function() {
var $node, $temp;
$temp = document.createElement('div');
$node = this.cloneNode(true);
$temp.appendChild($node);
return $temp.innerHTML;
},
set: function(markup) {
var $element, $temp, _i, _len, _ref, _results;
$temp = document.createElement('div');
$temp.innerHTML = markup;
while (this.firstChild) {
this.firstChild.parentNode.removeChild this.firstChild;
}
_ref = $temp.children;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
$element = _ref[_i];
_results.push(this.appendChild($element));
}
return _results;
},
enumerable: false,
configurable: true
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment