Creating a New Element

The DOM provides more than one way to create an element. You will examine some options in the examples that follow.

Using the createElement() Method

In this example, you will create a new SVG element using the createElement() method of the Document interface. You also will set the values of the attributes of the newly created element.

Listing 17.1 shows the code. Apart from the circle element that you will create using the DOM, the SVG document would be blank.

Listing 17.1. CreateCircle.svg: Creating a circle Element Using the DOM
 <?xml version='1.0'?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> <svg onload="Initialize(evt)"> <script type="text/javascript" ...

Get Sams Teach Yourself XML in 10 Minutes now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.