Re: Element.createElement proposal

Robert O'Callahan <[email protected]>
Newsgroups gmane.comp.mozilla.devel.dom
Organization Mozilla Corporation
Message-ID <[email protected]>
On 11/8/09 1:20 PM, Johnny Stenback wrote:
> On 08/10/2009 06:06 PM, Zack Weinberg wrote:
>> Johnny Stenback<[email protected]> wrote:
>>> What I don't like about svgElement.createElement() is that it seems a
>>> bit odd to have to find an element to create one, which makes the
>>> case where you're inserting SVG into a document where there is no
>>> existing SVG such that developers still need to type out that
>>> namespace URI they don't want to type out. svgElement.createChild()
>>> doesn't make any sense to me as there's no child relationship between
>>> the element you use for creating and the element that gets created.
>>
>> What's wrong with
>>
>> var parent = document.getElementById("putsvghere"); // HTML elt
>> var svg = parent.addChild('svg'); // HTML5 'svg' elt = SVG root elt
>> var circle = svg.addChild('circle', {...}); // SVG 'circle'
>
> What should that code do if you replace parent.addChild('svg') with
> parent.addChild('a')?

For simplicity I would say that e.addChild should always inherit the 
namespace of e.

> And does this always append, or insert at the
> beginning, what if I want to insert somewhere in the middle etc etc?

I think it should always append. The use cases for the other positions 
are much fewer and can be handled with existing DOM APIs.

The common case here is canvas-like scenarios where you already have an 
SVG container and you're adding a lot of shapes to it.

Rob
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.