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 23694 - Should element.getElementById() consider the element itself when searching
Summary: Should element.getElementById() consider the element itself when searching
Status: RESOLVED INVALID
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: DOM (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 normal
Target Milestone: ---
Assignee: Anne
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-10-31 22:27 UTC by Olli Pettay
Modified: 2013-11-03 23:48 UTC (History)
4 users (show)

See Also:


Attachments

Description Olli Pettay 2013-10-31 22:27:05 UTC
It is odd if getElementById can't be used reliably in a disconnected
subtree to find element by id.

Based on testing querySelector seems to have similar oddity, but
we don't need to copy its behavior here, IMO.
Comment 1 Boris Zbarsky 2013-11-01 00:08:20 UTC
SVGSVGElement.getElementById does _not_ consider the element itself.  Do we really want to break compat there?
Comment 2 Boris Zbarsky 2013-11-01 00:08:49 UTC
A possibility is to add an optional boolean argument, defaulting false, for whether to include the root, I guess...
Comment 3 Anne 2013-11-01 11:49:12 UTC
None of the getElement* methods behave this way. Ask web developers, they'll expect it to search among the descendants, not inclusive descendants.
Comment 4 Olli Pettay 2013-11-01 11:57:46 UTC
http://www.w3.org/TR/SVG/struct.html#__svg__SVGSVGElement__getElementById is vague, but implementations indeed don't include the root element of a subtree.
So, I guess we need to live with that oddity, and perhaps
add the boolean param later if needed.
Comment 5 Glenn Maynard 2013-11-03 23:48:27 UTC
We only "expect" it to because we've been bit by it and learned its weird behavior.  That doesn't mean it's how we *want* it to behave.

This can't be changed now, of course, but I definitely recall being annoyed at querySelector not matching the top element, and having to manually matchSelector it separately.  I don't know if it's worth adding a parameter, though (if so, it should be a dictionary parameter and not a bare boolean).

(If we add a function to search up the tree, eg. "find the nearest container that matches a selector", it absolutely needs to check the initial node, though.)