I'm new to SVG
, so I apologize in advance for my ignorance.
I created a fiddle, just playing around with things. http://jsfiddle.net/a46p8/
var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
svg.setAttribute('width','200');
svg.setAttribute('height','200');
var line = document.createElementNS('http://www.w3.org/2000/svg', 'line');
line.setAttribute('width', '0');
line.setAttribute('height', '0');
line.setAttribute('x1', '0');
line.setAttribute('y1', '0');
line.setAttribute('x2', '150');
line.setAttribute('y2', '150');
line.setAttribute('stroke', 'rgb(255,0,0)');
line.setAttribute('stroke-width', '2');
svg.appendChild(line);
var ct = document.getElementById('container');
ct.appendChild(svg);
Is there really no simpler way to setAttributes? For example, is it at all possible to combine them with something like this:
line.setAttribute('x1', '0', 'y1', '0', 'x2', '150', 'y2', '150');
Yea, I know it doesn't work when I try in the fiddle. But is there some way to do it? If not, what's the reason why you can't?