This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 27623 - A node.index() method for the ChildNode interface?
Summary: A node.index() method for the ChildNode interface?
Status: RESOLVED WORKSFORME
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
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-12-16 06:44 UTC by Glen Huang
Modified: 2014-12-16 15:54 UTC (History)
4 users (show)

See Also:


Attachments

Description Glen Huang 2014-12-16 06:44:04 UTC
Love the jquery-like ChildNode interface.

I wonder if it makes sense to add a node.index() method that returns the node's index. This would be very helpful when dealing with DOM ranges: range.setStart(node.parentNode, node.index())
Comment 1 Simon Pieters 2014-12-16 07:47:45 UTC
Alternatively maybe we could tweak the APIs that use indexes as input to also allow nodes as input:

range.setStart(node.parentNode, node)
Comment 2 Simon Pieters 2014-12-16 07:48:58 UTC
Or range.setStart(node)
Comment 3 Glen Huang 2014-12-16 07:52:04 UTC
This probably won't cut it, since sometimes

range.setEnd(node.parentNode, node.index() + 1); // or +2

is needed
Comment 4 Glen Huang 2014-12-16 08:12:38 UTC
It turns out we already have setStartBefore and the likes, which does exactly what Simon suggest.

I personally have no use for this method for now.

Not sure if should close the bug.
Comment 5 donjjordan 2014-12-16 15:54:23 UTC
Since a node.index() function is required by many of the DOM's internal algorithms (i.e. https://dom.spec.whatwg.org/#concept-tree-index), all of the DOM implementations already have a privately-defined method like this. If a use is ever found for this function outside of what is already provided by the DOM, then node.index() would be a freebie to expose in the IDL. For now, there is no point in cluttering up the API.