Programmatically creating the <svg> element

125 views
Skip to first unread message

Jeff Schiller

unread,
Aug 3, 2009, 11:34:22 PM8/3/09
to svg...@googlegroups.com
Hello,

I raised Issue 202

http://code.google.com/p/svgweb/issues/detail?id=202

but I should have asked here first, sorry about that.

Is there a way to programmatically create the <svg> element from
within HTML's JS?

Thanks,
Jeff

R. Masters

unread,
Aug 4, 2009, 12:33:13 AM8/4/09
to svg...@googlegroups.com

Jeff,

Yes there is*. See line 74:

http://code.google.com/p/svgweb/source/browse/trunk/samples/javascript-samples/svg_dynamic.html

*Unfortunately, this did not work last time I checked. Issue 177 was opened for it.

Regards,
Rick

Brad Neuberg

unread,
Aug 4, 2009, 1:26:29 AM8/4/09
to svg...@googlegroups.com, svg...@googlegroups.com
You mean a top level new svg document, or a nested svg element inside
another one? The answer is no on both unfortunately but they are both
on my radar.

Jeff Schiller

unread,
Aug 4, 2009, 1:43:21 AM8/4/09
to svg...@googlegroups.com
Hi Brad,

I'm talking about a top-level <svg> element in an <html> document.
The equivalent of this:

<html><body>
<div id="d">
<svg id="root"/>
</div>
</body></html>

But where root is created dynamically via JavaScript:

var d = document.getElementById("d")
d.appendChild( document.createElementNS("http://www.w3.org/2000/svg", "svg") )

This is exactly what Rick's example does at
http://code.google.com/p/svgweb/source/browse/trunk/samples/javascript-samples/svg_dynamic.html

Do you have any idea what form this is likely to take in the future?
i.e. would it just be the same DOM call: createElementNS() or
something else, perhaps the HTML5-ish createElement('svg') though not
sure how you would do that consider the IE DOM already has a
createElement() function. Ok, I'm still largely in the dark about how
your htc / DOM shim works.

I may be able to work around this, but can you give your best ETA? :)

Thanks,
Jeff

Brad Neuberg

unread,
Aug 4, 2009, 12:20:46 PM8/4/09
to svg...@googlegroups.com, svg...@googlegroups.com
The User Manual has a section on what the API for dynamically creating
svg roots will look like (though it's bot implemented yet). After
finishing the performance work and some other bugs and polishing the
demo.html file this is on my radar. Perhaps a month or 6 weeks?
Reply all
Reply to author
Forward
0 new messages