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

Re: Older Sibling?

From: Ray Whitmer <ray@xmission.com>
Date: Tue, 29 Feb 2000 07:36:03 -0700
Message-ID: <38BBD953.B98D33AC@xmission.com>
To: Thomas Ashe <Thomas.Ashe@Blackbaud.com>
CC: www-dom@w3.org
Thomas Ashe wrote:

> In looking through the DOM specs, I could not discern a way to do the
> following:
>
> Given two nodes of a common parent, identify which node precedes the other
> in the parent's ChildNodes nodelist.
>
> Is there such a creature in the current specs?

No.  I, too, would find one useful.  And different
implementations might optimize it differently if it were a
standard method in DOM.

Once nodes with a common parent are found,  trace previous
/ next in a loop (I do both simultaneously) and see which direction
one can be found from the other.  If the nodes are not known
to be siblings, the procedure is only a bit more complicated.

Unfortunately, this requires you to be able to detect whether
two node objects within a hierarchy represent the same node.
In some implementations, this can be done by using an ==
comparison on the object references, but there is no guarantee
that the same object will always be returned for a specific node,
so this order comparison cannot be performed portably, unless I
missed something.  The inability to compare node identity is an
omission that needs to be resolved.

Alternatively, it might be possible to use Level 2 optional ranges
to answer the question, by setting start and end, and checking
whether the range has collapsed using the isCollapsed attribute.
To me, this seems to be an appropriate use of ranges, if your
DOM implementation is level 2 and supports ranges.

Is anyone aware of a better approach?

Ray Whitmer
ray@xmission.com
Received on Tuesday, 29 February 2000 09:15:30 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:13:47 GMT