Re: Element.createElement proposal
Jonathan Watt <[email protected]>
| Newsgroups | gmane.comp.mozilla.devel.dom |
|---|---|
| Message-ID | <[email protected]> |
On 2009-08-11 1:38 AM, Johnny Stenback wrote:
> On 08/05/2009 01:52 AM, Jonathan Watt wrote:
>> Hi guys,
>>
>> I've been thinking about what we can do to simplify the creation of new elements
>> using the DOM. I came up with a few ideas in the SVG WG, and I wondered what you
>> think about the following one (and how implementable it is in Mozilla). Please
>> bear with me to the end of the email.
>>
>> It's really tedious and error prone that you have to do:
>>
>> c = document.createElement('NS-people-dont-know-or-want-to-type', 'circle');
>> c.setAttribute('cx', '10');
>> c.setAttribute('cy', '10');
>> c.setAttribute('r', '10');
>> svgElement.appendChild(c);
>>
>> Much better would be:
>>
>> c = svgElement.createElement('circle', { cx: 10, cy: 10, r: 10} );
>> svgElement.appendChild(c);
>>
>> or even just:
>>
>> c = svgElement.createChild('circle', { cx: 10, cy: 10, r: 10} );
>>
>
> I still think element creation belongs on document objects more than it
> does on elements. How about adding a createSVGElement method to our
> documents instead? Since it'd be a new method, we could change the
> signature of that to do things that are more developer friendly? Given
> that HTML5 supports mixed in SVG, this would make some amount of sense
> at least on HTML documents. Same goes for MathML too, I guess...
Hmm. I'm not all that keen on the idea of adding separate methods like
createSVGElement, createMathMLElement and createXULElement (and
createHTMLElement?) for each namespace we may support now or in the future.
Allowing elements to create more elements on the other hand is less of a problem
to me I guess.
Jonathan