Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating SVG graphics using Javascript?

How can I create SVG graphics using JavaScript?

Do all browsers support SVG?

like image 911
user123757 Avatar asked Jun 23 '09 19:06

user123757


People also ask

Can we use JavaScript in SVG?

JavaScript can be added anywhere in an SVG document between the opening and closing <svg> tags. In general, a script should be placed at the end of the document to avoid blocking and allow the script complete access to the DOM.

How do I create a SVG image?

Choose File > Save As from the Menu Bar. You can create a file and then choose File > Save As to save the file. In the save window, change the Format to SVG (svg) and then click Save. Change the format to SVG.

How do you code SVG in HTML?

SVG images can be written directly into the HTML document using the <svg> </svg> tag. To do this, open the SVG image in VS code or your preferred IDE, copy the code, and paste it inside the <body> element in your HTML document.

Is SVG HTML or XML?

SVG is an application of XML and is compatible with XML 1.0 and with the Namespaces in XML specification. However, when SVG content is included in HTML document, the HTML syntax applies and may not be compatible with XML.


1 Answers

Have a look at this list on Wikipedia about which browsers support SVG. It also provides links to more details in the footnotes. Firefox for example supports basic SVG, but at the moment lacks most animation features.

A tutorial about how to create SVG objects using Javascript can be found here:

var svgns = "http://www.w3.org/2000/svg"; var svgDocument = evt.target.ownerDocument; var shape = svgDocument.createElementNS(svgns, "circle"); shape.setAttributeNS(null, "cx", 25); shape.setAttributeNS(null, "cy", 25); shape.setAttributeNS(null, "r",  20); shape.setAttributeNS(null, "fill", "green");  
like image 135
schnaader Avatar answered Sep 20 '22 21:09

schnaader