setAttributeNodeNS

setAttributeNodeNS

テスト・ケース

歴史

[2] DOM水準3で、自分自身を置換しようとしても効果はないと明記されました。

しかし、その場合何が返されるのかは不明です。

実装

[3] DOM3 は他の文書節点を指定したら WRONG_DOCUMENT_ERR になるとしていますが、 実際には自動的に adopt されます。

[4] >>2 の場合には自分自身が返されます。

[5] Chrome ではおそらく setAttributeNodesetAttributeNodeNS は同じで、 namespaceURIlocalName でどれが置き換えられるか決まります。 Firefox では setAttributeNodesetAttribute と同じように QName が最初に一致した節点を置き換えるようで、 その結果不整合が生じることもあるようです。

[6] Firefox では非推奨との警告が出ます。

[7] Define getAttributeNode[NS] and removeAttributeNode · 5a881d9 · whatwg/dom ( ( 版)) <https://github.com/whatwg/dom/commit/5a881d9b5f328f8e32f0fa8e73b4e8799772cb0c>

[8] Define Element.prototype.setAttributeNode[NS], removeAttributeNode, Name... · 12d0114 · whatwg/dom ( ( 版)) <https://github.com/whatwg/dom/commit/12d011437faef5ada7b816c94aab39b10cdb2f4b>

[9] Define Element.prototype.setAttributeNode[NS], removeAttributeNode, Name... · 12d0114 · whatwg/dom ( ( 版)) <https://github.com/whatwg/dom/commit/12d011437faef5ada7b816c94aab39b10cdb2f4b>

[10] <http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C!DOCTYPE%20html%3E%0A%3Cbody%3E%0A%3Cscript%3E%0A%20%20var%20el%20%3D%20document.createElement%20(%27a%27)%3B%0A%20%20el.setAttributeNS%20(%22a%22%2C%20%22a%3Ahref%22%2C%20%22foo%22)%3B%0A%20%20var%20attr%20%3D%20document.createAttributeNS%20(%22a%22%2C%20%27b%3Ahref%27)%3B%0A%20%20attr.value%20%3D%20%22bar%22%3B%0A%20%20el.setAttributeNode%20(attr)%3B%0A%20%20document.body.appendChild%20(el)%3B%0A%3C%2Fscript%3E>: Chrome では「A a:href="bar"」、Firefox では「A a:href="foo" b:href="foo"」 になります。 setAttributeNodeNS にすると、 Chrome では「A a:href="bar"」、Firefox では「A b:href="bar"」になります。

[11] <http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C!DOCTYPE%20html%3E%0A%3Cbody%3E%0A%3Cscript%3E%0A%20%20var%20el%20%3D%20document.createElement%20(%27a%27)%3B%0A%20%20el.setAttribute%20(%22href%22%2C%20%22foo%22)%3B%0A%20%20var%20attr%20%3D%20document.createAttribute%20(%22hRef%22)%3B%0A%20%20attr.value%20%3D%20%22bar%22%3B%0A%20%20el.setAttributeNode%20(attr)%3B%0A%20%20document.body.appendChild%20(el)%3B%0A%3C%2Fscript%3E>: Chrome では「A href="bar"」、Firefox では「A hRef="bar"」 になります。 setAttributeNodeNS にすると、 Chrome では「A href="bar"」、Firefox では「A href="foo" hRef="foo"」になります。

[12] Fix #117: alias setAttributeNode to setAttributeNodeNS and setNamedIt… · whatwg/dom@a0042ff ( 版) <https://github.com/whatwg/dom/commit/a0042ffbc46d4382427fa3b238fa61b800a4f07c>

[13] Fix the set an attribute algorithm · whatwg/dom@f8089df ( 版) <https://github.com/whatwg/dom/commit/f8089df55baed0c2334725af45357ba659c212cd>

[14] Add support for custom elements · whatwg/dom@7f63535 ( 版) <https://github.com/whatwg/dom/commit/7f63535da39a1cbf7f8f68563abc6f05f760990a>

[15] Add [CEReactions] annotations to mutating methods · whatwg/dom@3cd02d1 ( 版) <https://github.com/whatwg/dom/commit/3cd02d139c159a31fbb400e03932652c72fc7812>