6

I'm trying to use document.createElement('circle') to work with svgs but Chrome creates a end tag to circle giving

<circle></circle>

which results of an error. How can I create an element without an ending that?

3
  • Why don't you want an end tag?
    – Mrchief
    Aug 9, 2011 at 21:14
  • Because the end tag causes chrome to not display the circle...
    – SBSTP
    Aug 9, 2011 at 21:16
  • 2
    End tags are never optional (unless you are using self-closing tag syntax) for XML elements … and noting will generate an end tag when you use createElement. The parser turns an XML document into a DOM (where there are only nodes, not tags). You can manipulate it all you like. If you turn it back into an XML document, then you get tags.
    – Quentin
    Aug 9, 2011 at 21:24

3 Answers 3

8

You might want to take a look at this article

SVG Scripting with JavaScript Part 1: Simple Circle

The method you're looking for is:

var circle = document.createElementNS("http://www.w3.org/2000/svg", "circle");

Edit: Credit where credit is due

Stackoverflow: Creating SVG graphics using javascript?

4

try using document.createElementNS:

var circle = document.createElementNS("http://www.w3.org/2000/svg","circle");
-2

Try to use :

document.createElementNS('circle')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.