[51] 属性は、 要素に関する付加情報を記述するものです。
[52] 属性は、属性名と属性値の組です。要素にはいくつでも属性を指定できますが、 同じ属性名のものは1つしか指定できません。 つまり要素の属性リストは要素ごとの写像と捉えることができます。
[53] 具体的にどのような属性名と属性値を指定できるのかは、要素の種類や文脈によって異なります。
[40] 著者は、属性や属性値を、その想定用途以外の目的で使ってはなりません >>39。これは、文書を正しく処理できるようにするための要件です >>39。
[38] 著者は、属性や属性値を、適用可能な仕様書で認められていないのに使ってはなりません >>39。 これは、言語の将来の拡張の余地を残すためです >>39。
[42] どのような属性を使って良いかは、要素ごとに決められています。
[43] いくつかの属性は、多数の要素で共通して使うことができます。 そうした属性を、次のように分類しています。
[44] なお、同じ属性名であっても、要素によって異なる意味を持つことがあります。
[45] ほとんどの要素は、特定の属性のみを認め、それ以外を禁止しています。 例外的に、次の要素は、 (一定の制約の元で) 著者が任意の名前の属性を使うことを認めています。
data-*
属性を多くの要素で使えます。Attr
インターフェイス (DOM)#✎[13] DOM1 で属性節が持つことが出来る子節の種類は、 Text と EntityReference の2種類です。
[14] DOM の文書木・節モデルの中では、属性はやや特殊な位置づけになっています。
Attr
節は、文書木の中には現れません。null
。)DocumentFragment
節の直接の子要素にはできません。nodeValue
では属性値文字列が、 childNodes
では Text
節及び EntityReference
節の組合せによる属性値の表現が得られます。読取専用属性 | name | 名前 | [DOM1] |
読取専用属性 | specified | 指定されているか | [DOM1] |
属性 | value | 値 | [DOM1] |
読取専用属性 | ownerElement | 親要素節 | [DOM2] |
Element
節だけです。IDREFS
型属性値の3番目の ID
を取り出したい、という場合には、属性値全体を受け取ってそれを勝手に解析する必要があります。[16] Attr
節点の子孫である EntityReference
節点の子供は
EntityReference
または
Text
しか認められない・・・はずですが、
DOM の仕様書にはそんなこと一言も書いてないな。
[17] DOM の仕様書には Attr
は他の種類の Node
とは違って
Element
と切り離せないものだとかなんとか説明がありますが、
それでいてなぜか Attr
が単独で存在できたりします。
それ自体は値を持たずに子孫がいたり。
Interface AttrExtended IDL Definition attribute boolean type; Attributes isClassAttribute of type boolean Whether the attribute is a class attribute or not. If it is a class attribute, the value is "true"; otherwise, "false". Note that not all attributes whose local name is "class" is a class attribute.
[19] Chrome は DOM3 の規定通り Attr
の子供に Text
が来る構造になっていて、通常の Node
として操作できます。
しかし WinIE や Gecko は DOM4 の規定のように Attr
の値を節点としては扱っていません。 childNodes
は空ですし、
appendChild
は HierarchyRequestError
になります。
[20] IRC logs: freenode / #whatwg / 20121213 ( ( 版)) http://krijnhoetmer.nl/irc-logs/whatwg/20121213#l-339
[21] Re: [DOMCore] Attr ( (Jonas Sicking 著, 版)) http://lists.w3.org/Archives/Public/public-webapps/2010JulSep/0797.html
[22] Attr - Document Object Model (DOM) | MDN ( ( 版)) https://developer.mozilla.org/en/docs/DOM/Attr
[36] 要素の属性が変化した時の要素・属性依存の動作を記述するためのフックが DOM Standard で属性変更手順群として定義されています。 >>11。
[37] 次のものに関する属性変更手順群が定義されています。
[29] 仕様書上ではこのフックを使っていませんが、属性が変化した時に次のような処理が連動して行われます。
[46] カスタム要素反応に関する処理は、仕様書上は属性変更手順群ではなく、 属性変更手順群の直前に実行する処理として規定されています。
- (141) (要素の) 属性 [attribute (of an element)]
- 型及び内容を除く特質。 JIS X 4151‐1992 3.
[2] SGML では要素型や要素の内容も広い意味では属性
に含まれます
JIS X 4151‐1992 参考。 SGML 規格本体で特に
要素の属性
として定義されているものはそれ以外、
すなわち属性指定で指定され得る形式的な属性のみを指すべく >>1
のように説明されています。
仕様書:
[7] IRC logs: freenode / #whatwg / 20090925 ( 版) http://krijnhoetmer.nl/irc-logs/whatwg/20090925#l-298
attribute::
(@
) 軸 (XPath 1.0)#✎[30] Chrome でも Firefox でも、仕様通り xmlns
名前空間の属性は
XPath データモデル上の属性節点としては存在しません。
[31] Touch Events ( ( 版)) https://dvcs.w3.org/hg/webevents/raw-file/v1/touchevents.html#webidl-conform
[32] Re: Moving Touch Events v1 to Recommendation ( (Doug Schepers 著, 版)) http://lists.w3.org/Archives/Public/public-webevents/2013OctDec/0000.html
[33] Accessible Rich Internet Applications (WAI-ARIA) 1.0 ( ( 版)) http://www.w3.org/WAI/PF/aria/complete#def_attribute
[34] XQuery and XPath Data Model 3.0 ( ( 版)) http://www.w3.org/TR/xpath-datamodel-3/#AttributeNode
[35] Bug 25460 – muted and mediagroup should not be special-cased for the parser ( ( 版)) https://www.w3.org/Bugs/Public/show_bug.cgi?id=25460
The Infoset terms "Element Information Item" and "Attribute Information Item" are shortened to "element" and "attribute" respectively. Therefore, when this specification uses the term "element", it is referring to an Element Information Item, and when it uses the term "attribute", it is referring to an Attribute Information Item.
[10] Fix #489: 'src attribute is missing' is equal to 'no src attribute sp… · whatwg/html@3f7fda0 ( 版) https://github.com/whatwg/html/commit/3f7fda0be2759dc36480c8acc037d149ee831aea
[12] Use a single concept for attribute changes · whatwg/dom@4b291d1 ( 版) https://github.com/whatwg/dom/commit/4b291d1a91a1e8b59997d4b021137d809706bd37
[47] Integrate with the Referrer Policy spec, part 1 of n ( (domenic著, )) https://github.com/whatwg/html/commit/6a7318072f340ad45229df171245d70d8621c2fe
[48] Make Attr inherit from Node again (annevk著, ) https://github.com/whatwg/dom/commit/625a0747f137454c155a7b577a9e45be1aa35a34
[49] ATTRIBUTE_NODE and SHOW_ATTRIBUTE are no longer historical (foolip著, ) https://github.com/whatwg/dom/commit/dc3990d2678375a17fa05f3f4de99da23077c229
[50] Further Attr node fixes for compareDocumentPosition() (annevk著, ) https://github.com/whatwg/dom/commit/0e17e05b7b0273799b853c4782b2eac9a88fdea1
[54] Elements with duplicated attributes are not nonceable. (mikewest著, ) https://github.com/w3c/webappsec-csp/commit/649393514b9aaf9277bfd21ee1834f4befd029be
[55] Consider hiding `nonce` content attributes. · Issue #2369 · whatwg/html () https://github.com/whatwg/html/issues/2369
<html lang=”ja”>
[57] Editorial: Clarify that attributes and operations may be namespace me… (littledan著, ) https://github.com/heycam/webidl/commit/6b9ad923b1c2ce7d128790dfceb4dda33adb9c89
[58] Editorial: embrace that attributes are objects (annevk, , ) https://github.com/whatwg/dom/commit/0038d097f5cad2a7ffdbe75c234b58960aa320f6
[59] Editorial: embrace that attributes are objects by annevk · Pull Request #805 · whatwg/dom () https://github.com/whatwg/dom/pull/805