Skip to content

Instantly share code, notes, and snippets.

@Torthu
Created February 12, 2014 13:30
Show Gist options
  • Select an option

  • Save Torthu/8955564 to your computer and use it in GitHub Desktop.

Select an option

Save Torthu/8955564 to your computer and use it in GitHub Desktop.
Add textNode to g-element in SVG
// textToDisplay = whatever you want to fill the textnode with
// elementId g element id (that the textnode will be appended to)
function addTextToG(textToDisplay, elementId) {
// create svg text node
var textNode = document.createElementNS("http://www.w3.org/2000/svg","text");
textNode.appendChild(document.createTextNode(textToDisplay));
// append created textnodes to g nodes
document.getElementById(elementId).appendChild(textNode);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment