Reputation: 81
I create a svg area. As things happen in the document, I want to display text strings in the svg area in xy coordinates within the svg area where I click.
How can I append a new text element to given xy coordinates in the svg area as these things happen?
Upvotes: 0
Views: 62
Reputation: 101820
var svg = document.getElementById("id-of-my-svg");
var text = document.createElementNS("http://www.w3.org/2000/svg", "text");
text.setAttribute("x", clickX);
text.setAttribute("y", clickY);
text.appendChild( document.createTextNode("Some text") );
svg.appendChild(text);
Upvotes: 1