Skip to content

Instantly share code, notes, and snippets.

@xcarpentier
Created January 20, 2020 13:31
Show Gist options
  • Save xcarpentier/fd0ec3ff1693b6a9e9e33254274b0c31 to your computer and use it in GitHub Desktop.
Save xcarpentier/fd0ec3ff1693b6a9e9e33254274b0c31 to your computer and use it in GitHub Desktop.
document.body.innerHTML = '<svg></svg>'
const SVG = document.getElementsByTagName('svg')[0]
const Text = document.createElementNS("http://www.w3.org/2000/svg", "text")
Text.setAttribute('y', 10)
Text.appendChild(document.createTextNode("this is the text content"))
SVG.appendChild(Text)
const Rect = document.createElementNS("http://www.w3.org/2000/svg", "rect")
Rect.setAttribute('x', '0')
Rect.setAttribute('y', '10')
Rect.setAttribute('width', '10')
Rect.setAttribute('height', '10')
Rect.setAttribute('style', 'fill:blue')
SVG.appendChild(Rect)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment