* 処理

[7] [VAR[節点]]と[VAR[識別子]]について[DFN[識別子により要素を取得]]する処理は、次の場面で使われます。
[FIG(list middle)[
- [CODE(DOMm)@en[getElementById]]
- [CODE(DOMi)@en[HTMLElement]] として[[反映]]
]FIG]

* 関連

- [CODE(DOMm)@en[[[getElementsByName]]]]
- [CODE(JS)@en[[[document.all]]]]
- [CODE(DOMm)@en[[[getElementsByTagName]]]]
- [CODE(DOMm)@en[[[getElementsByClassName]]]]
- [CODE(DOMm)@en[[[querySelector]]]], [CODE(DOMm)@en[[[querySelectorAll]]]]

* 歴史

** W3C DOM 時代

[3]
仕様書:
- [[DOM水準1]]
-- HTML モジュール [CODE(DOMi)[[[HTMLDocument]]]] 界面 
[CODE(DOMm)[getElementById]] メソッド
<IW:DOM1:"level-one-html.html#ID-36113835">
- [[DOM水準2]]
-- 中核モジュール [CODE(DOMi)[[[Document]]]] 界面 
[CODE(DOMm)[getElementById]] メソッド
<IW:DOM2:"Core/core.html#ID-getElBId">
- [[DOM水準3]]
-- 中核モジュール [CODE(DOMi)[[[Document]]]] 界面 
[CODE(DOMm)[getElementById]] メソッド
<IW:DOM3:"Core/core.html#ID-getElBId">
-- XPath モジュール適合性
<IW:DOM3:"XPath/xpath.html#Conformance">

** getElementById method (DOM 2+ Document 界面)

[1] Method
[CODE[[VAR[([CODE[(DOMi)[[[Element]]]])]] := [VAR(DOMi)[[[Document]]]].[CODE(DOMm)[getElementById]] ([VAR[[[[CODE(DOMi)[[[DOMString]]]]) [CODE(DOMp)[elementId]]]])]]]]
を使うと、文書内で[[識別子属性]] [VAR(DOMp)[elementId]]
を持つ[[要素節]]を得ることができます。

[2]
[[妥当]]でないために同じ識別子を持つ要素が複数あるときの動作は未定義です。

該当するものがないときや、識別子属性を実装が知らない時は
[CODE(DOM)[[[null]]]] が返ります。

例外はありません。

[4]
文書木から削除されているとか [CODE(DOMi)[[[Entity]]]] 木に存在している識別子つき要素節点とは一致するのでしょうかね?

**


[8]
[CITE@en[Re: Selectors API: Multiple elements with the same ID from Boris Zbarsky on 2007-01-28 (public-webapi@w3.org from January 2007)]] ([[Boris Zbarsky (bzbarsky@mit.edu)]] 著, [CODE[2007-01-28 13:54:06 +09:00]] 版) <http://lists.w3.org/Archives/Public/public-webapi/2007Jan/0158>
([[名無しさん]])

[9]
[CITE[subtech - MisuzillaSubtechImpl - document.getElementById('name');]] ([CODE[2007-05-26 11:40:20 +09:00]] 版) <http://subtech.g.hatena.ne.jp/mayuki/20070525/1180091603>
([[名無しさん]] [WEAK[2007-05-26 02:41:40 +00:00]])

[CITE[document.getElementById('name'); - ういはるかぜの化学 - subtech]] ([TIME[2019-07-27 17:12:04 +09:00]]) <https://web.archive.org/web/20190727081152/http://subtech.g.hatena.ne.jp/mayuki/20070525/1180091603>


[10]
[[DOM水準3]]によると[[識別子属性]]かどうかの判断に [CODE(DOMa)@en[[[isId]]]]
を使うことが[[実装]]には期待されています。

;; 期待だけかよ。。。



[12]
[CITE@en[Beware of id and name attribute mixups when using getElementById in Internet Explorer | 456 Berea Street]] ([[Roger Johansson]] 著, [TIME[2008-03-16 11:16:02 +09:00]] 版) <http://www.456bereastreet.com/archive/200802/beware_of_id_and_name_attribute_mixups_when_using_getelementbyid_in_internet_explorer/>
([[名無しさん]])

[13] [CITE[Bug 6006 - document.getElementById does not behave in the same way as Internet Explorer (Win)]] ([TIME[2008-11-29 18:07:10 +09:00]] 版) <https://bugs.webkit.org/show_bug.cgi?id=6006>

[14] [CITE[Opera の id, name 問題 - IT戦記]] ([TIME[2009-02-02 02:01:48 +09:00]] 版) <http://d.hatena.ne.jp/amachang/20071110/1194655704>


[15] [CITE[Document Structure – SVG 1.1 (Second Edition)]]
( ([TIME[2011-08-10 12:35:27 +09:00]] 版))
<http://www.w3.org/TR/2011/REC-SVG11-20110816/struct.html#__svg__SVGSVGElement__getElementById>

[16] [CITE[''''''[''''''whatwg'''''']'''''' Proposal: Adding methods like getElementById and getElementsByTagName to DocumentFragments]]
( ([TIME[2013-10-19 00:27:18 +09:00]] 版))
<http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2013-October/041211.html>

[17] [CITE[Move getElementById() from Document to ParentNode (now applies to Elemen... · 1e953d1 · whatwg/dom]]
( ([TIME[2013-11-13 11:37:54 +09:00]] 版))
<https://github.com/whatwg/dom/commit/1e953d1b2205dbf0ca78af82e6fd7c59a04c347e>

[18] [CITE[Move getElementById() from Document to ParentNode (now applies to Elemen... · 1e953d1 · whatwg/dom]]
( ([TIME[2013-12-27 06:47:39 +09:00]] 版))
<https://github.com/whatwg/dom/commit/1e953d1b2205dbf0ca78af82e6fd7c59a04c347e>

[19] [CITE[Remove getElementById from Element. https://www.w3.org/Bugs/Public/show_... · f71d7de · whatwg/dom]]
( ([TIME[2013-12-27 06:56:51 +09:00]] 版))
<https://github.com/whatwg/dom/commit/f71d7de304e1ee25573279157dd6ce1c2aa2c4f2>

[20] [CITE@en-US[XML Binding Language (XBL) 2.0]]
( ([TIME[2007-03-16 22:20:16 +09:00]] 版))
<http://www.w3.org/TR/2007/CR-xbl-20070316/#getelementbyid>

[5] [CITE@en[Restore SVGSVGElement.getElementById. Closes #182.]]
([[nikosandronikos]]著, [TIME[2016-07-01 15:01:30 +09:00]])
<https://github.com/w3c/svgwg/commit/b842fc3a1d2b5f5330220870e1a097a62e696868>

[6] [CITE@en[for getElementById, clarify result when multiple elements have the sa…]]
([[nikosandronikos]]著, [TIME[2016-07-04 09:48:38 +09:00]])
<https://github.com/w3c/svgwg/commit/0d66a1092e66226e59f6868d234c83f64230318a>