Created
March 19, 2019 15:11
-
-
Save ipatch/f5695854a2f70212ebc5b0a5122f1b24 to your computer and use it in GitHub Desktop.
add svg to DOM using Javascript
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
| // I'm using Webpack to build a bundle of a simple index.js | |
| // ...and I'm trying to add a SVG element to the DOM using Webpack, which I believe is working, | |
| // ...however Webpack is unable to locate the path to the SVG or Webpack is not properly handling the SVG | |
| // setup namespace for SVG | |
| var svgns = 'http://www.w3.org/2000/svg'; | |
| var svg = document.createElementNS(svgns, 'svg'); | |
| document.body.appendChild(svg); | |
| svg.setAttribute('version', '1.1'); | |
| svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg'); | |
| // baseProfile | |
| // width | |
| // height | |
| // bring in external svg | |
| var use1 = document.createElementNS(svgns, "use"); | |
| use1.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', './images/purple-circle-plain.svg#circle-purple'); | |
| svg.appendChild(use1); |
Author
ipatch
commented
Mar 19, 2019

Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment