Skip to content

Instantly share code, notes, and snippets.

@fuzzypawzz
Created February 29, 2020 12:11
Show Gist options
  • Save fuzzypawzz/7c25d3c2ea05df52e7e74952fd718da6 to your computer and use it in GitHub Desktop.
Save fuzzypawzz/7c25d3c2ea05df52e7e74952fd718da6 to your computer and use it in GitHub Desktop.
SVG Constructor
/**
* SVG ICON CONSTRUCTOR
* @constructor
* @param {string} svgId The reference ID for the SVG (for use with the 'use' svg)
* @param {string} className Class of the SVG's parent element
*/
function Svg(svgId, className) {
this.svgId = svgId;
this.className = className;
this.createSvg = function () {
// Create the parent namespace SVG element
var namespace = document.createElementNS("http://www.w3.org/2000/svg", "svg");
namespace.setAttribute("class", className);
// namespace.className = this.className;
// Create the SVG use (shadow)
var use = document.createElementNS("http://www.w3.org/2000/svg", "use");
use.setAttributeNS(null, "href", "#".concat(svgId));
// Append element as child of the parent
namespace.appendChild(use);
return namespace;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment