Re: modifying the DOM WAS: Node append

On Mon, Oct 3, 2011 at 2:39 PM, Boris Zbarsky <bzbarsky@mit.edu> wrote:

> On 10/3/11 5:30 PM, Ojan Vafai wrote:
>
>> Specifically, lets add the following methods to Node:
>> prepend(nodeish) - Adds to the start of the node.
>> append(nodeish) - Adds to the end of the node.
>> before(nodeish) - Adds before the node.
>> after(nodeish) - Adds after the node.
>> replace(nodeish) - Replaces the node.
>> remove() - Removes the node.
>>
>
> No matter what else, we _have_ to do the remove thing!
> foo.parentNode.removeChild(**foo) is just .... <sigh>.
>
> The only worry with adding these is on* attributes that might happen to use
> those barewords and expect to hit global scope.  Do we have any data on such
> things?  (Note that we've had problems with that sort of thing in the past,
> e.g. when inputs grew a 'list' property.)


I don't know how we can test for this without just trying it. We could turn
this on only in something like the Chromium dev channel for a few weeks and
see if we get bug reports.

A quick search on Google code search doesn't find anything, which is
promising, but this is a difficult thing to search for.


> 1. node, string, array, nodelist
>> 2. node, string, array, nodelist, number, bool, undefined, null
>> 3. node, string, anything with a length property is treated as an array,
>> anything else is toString'ed.
>>
>
> And for option 2 anything else throws?
>

That's what I had in mind.


> Note that in webidl terms, "array", "nodelist", and "anything with a length
> property" are sort of the same thing last I checked....
>

I'm OK with that. So, a 4th option which is now the one I have preference
for :).

4. node, string, number, bool, undefined, null, anything with a length
property


>
> -Boris
>

Received on Monday, 3 October 2011 21:54:53 UTC