Bug 16919 - Make element traversal members available on more nodes
Summary: Make element traversal members available on more nodes
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: DOM (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Anne
QA Contact: public-webapps-bugzilla
Depends on:
Reported: 2012-05-03 14:25 UTC by Simon Pieters
Modified: 2012-11-27 18:40 UTC (History)
6 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Simon Pieters 2012-05-03 14:25:49 UTC
If you have foo and want the next element sibling, it makes sense to just use nextElementSibling even if foo is not an element. Currently nextElementSibling is only defined on Element. The same argument goes for the other element traversal members.

Specifically, I think the following makes sense:

on Document, DocumentFragment, Element

on DocumentType, Element, CharacterData

I think this is similar to the new mutation methods (prepend() et al).
Comment 1 Marat Tanalin | tanalin.com 2012-05-03 15:38:51 UTC
Comment 2 Erik Arvidsson 2012-11-09 17:19:33 UTC
Wouldn't previousElementSibling and nextElementSibling be useful on Node too?
Comment 3 Anne 2012-11-09 17:27:48 UTC
Node - (DocumentType, Element, CharacterData) = (Document, DocumentFragment), so probably not?
Comment 4 Anne 2012-11-09 17:28:05 UTC
But it sounds like in general you think this is a good idea?
Comment 5 Erik Arvidsson 2012-11-09 18:00:26 UTC
(In reply to comment #4)
> But it sounds like in general you think this is a good idea?

Yes. It sounds like an improvement.

The reason why I think nextElementSibling makes sense for all Nodes is that it would give the next sibling node that is an Element. Conceptually nextElementSibling is just:

Object.defineProperty(Node.prototype, 'nextElementSibling', {
  get: function() {
    for (var next = this.nextSibling;
         next && next.nodeType !== Node.ELEMENT_NODE;
         next = next.nextSibling);
    return next;
Comment 6 Anne 2012-11-09 18:23:22 UTC
Maybe comment 3 was too cryptic. Simon is proposing to put previousElementSibling and nextElementSibling on all nodes, except for Document and DocumentFragment, where they are never useful, I think.