Y
Yansky
Hi, I've been learning SVG lately and I'm a bit confused about
namespaces and how it relates to SVG. This was the code I started out
with (firefox only):
document.firstChild.nextSibling.setAttribute('xmlns', 'http://
www.w3.org/1999/xhtml');
document.firstChild.nextSibling.setAttribute('xmlns:svg', 'http://
www.w3.org/1999/xhtml');
var se = document.createElement('div');
se.setAttribute('style','width:300px;height:100px;float:left;');
se.innerHTML='<svg width="100%" height="100%">'+
'<rect width="300" height="100" style="fill:rgb(0,0,255);stroke-width:
1;stroke:rgb(0,0,0)"/>'+
'</svg>';
document.body.appendChild(se);
But that didn't seem to work. It turned out I needed to use
document.createElementNS().
http://pastebin.ca/1274898
But I don't understand why this is. I thought createElementNS() was
only used in XUL. Why does the namespace need to be set when creating
an SVG element?
namespaces and how it relates to SVG. This was the code I started out
with (firefox only):
document.firstChild.nextSibling.setAttribute('xmlns', 'http://
www.w3.org/1999/xhtml');
document.firstChild.nextSibling.setAttribute('xmlns:svg', 'http://
www.w3.org/1999/xhtml');
var se = document.createElement('div');
se.setAttribute('style','width:300px;height:100px;float:left;');
se.innerHTML='<svg width="100%" height="100%">'+
'<rect width="300" height="100" style="fill:rgb(0,0,255);stroke-width:
1;stroke:rgb(0,0,0)"/>'+
'</svg>';
document.body.appendChild(se);
But that didn't seem to work. It turned out I needed to use
document.createElementNS().
http://pastebin.ca/1274898
But I don't understand why this is. I thought createElementNS() was
only used in XUL. Why does the namespace need to be set when creating
an SVG element?