creating a rectangle with dom

Discuss SVG code, accessible via the XML Editor.
katun89
Posts: 12
Joined: Sat Jan 08, 2011 12:57 pm

creating a rectangle with dom

Postby katun89 » Sat Jan 22, 2011 10:21 am

Guys I'm trying to draw the following

<rect id="redcardback2"width="57" height="61" x="1624" y="270" style="fill:#010000;fill-opacity:1;fill-rule:nonzero;stroke:#c70000;stroke-width:2;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke- dasharray:none;display:inline;enable-background:new" />

at the loading of the xml (svg) page. What am I doing wrong?

[CODE]
<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:ev="http://www.w3.org/2001/xml-events"
onload="drawCard()" >

<script type="text/javascript">

<![CDATA[

function drawCard()
{
newCardBack = document.createElement("rect");
newCardBack.setAttribute("id", "redcardback2");
newCardBack.setAttribute("width", 57);
newCardBack.setAttribute("height", 61);
newCardBack.setAttribute("x", 1624);
newCardBack.setAttribute("y", 270);
newCardBack.setAttribute("style", "fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#c70000;stroke-width:2;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;display:inline;enable-background:new");

/* ottengo l'elemento root della pagina */
svg = document.getElementsByTagName("svg");
svg[0].appendChild(newCardBack);
alert("io");
}

]]>
</script>
</svg>
[CODE]

Return to “SVG / XML Code”