W3C home > Mailing lists > Public > www-dom@w3.org > January to March 2013

new DOM4 insertions methods and return values

From: Jake Verbaten <raynos2@gmail.com>
Date: Tue, 15 Jan 2013 17:52:07 -0800
Message-ID: <CAMCMjp26u+AHcOdY1OorTYsV0NEHin=M_5Ef-SL5WeBr6a5TjQ@mail.gmail.com>
To: "www-dom@w3.org" <www-dom@w3.org>
The older DOM mutation methods like

Node appendChild(Node node);

returned the node you inserted

The newer DOM mutation methods like

void append((Node or DOMString)... nodes);

return void instead.

It would be useful if append returned either the single node or a
DocumentFragment

use-case is

```js
var style = document.head.append(
  document.createElement("style"))

style.type = "text/css"
style.textContent = "..."
```

It's simply less verbose for the common case for the new insertion methods
to return the node they operated on.

In the case you pass multiple nodes it should do the same as
`document.appendChild(someDocumentFragment)` does which is return the
document fragment you passed in (even though it's empty).

I've also written and maintain polyfills for those mutation methods and
have just landed a commit to return the values (
https://github.com/Raynos/insert/commit/3c823876bbac99638c56bc27ab043481587357c6
)
because the void return type was annoying.
Received on Wednesday, 16 January 2013 01:52:34 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 16 January 2013 01:52:36 GMT