W3C home > Mailing lists > Public > www-dom@w3.org > October to December 2011

[DOM4] parent method

From: Ojan Vafai <ojan@chromium.org>
Date: Thu, 15 Dec 2011 14:41:08 -0800
Message-ID: <CANMdWTueVK_J0UUC3VYiJidwpAcyQQYhaNc+DhGpOupOeGHwkQ@mail.gmail.com>
To: www-dom@w3.org
Another jquery inspired addition: we should add a "parent" method to Node
that takes a CSS selector or a function. It walks up the tree until it
finds a node that matches the selector/function.

node.parent() <-- returns node.parentNode
node.parent('div') <-- returns the first ancestor of node (walking up) that
is a div
node.parent(function(ancestor) { return ancestor.getAttribute("foo") ==
"bar" }) <-- returns the first ancestor of node whose "foo" attribute has
the value "bar"

Open questions:

1. Should all selectors be allowed or just simple selectors? The former is
easier to understand and more powerful but also easy to shoot yourself in
the foot with (e.g. combinators can easily result in n^2 walks of the
ancestor chain).

2. What should happen in the following cases? My intuition is that they
should all return either null or node.parentNode, but I don't feel strongly.

I also think we should add "next" and "previous" that do the same thing as
"parent" except they walk the sibling list, but I'm less convinced those
are as useful.
Received on Friday, 16 December 2011 02:42:06 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 22:36:59 UTC