This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.
http://dom.spec.whatwg.org/#interface-element [[ When an element's id attribute is removed, unset the element's ID. ]] ...or when it is set to the empty string?
Set to empty string not removed id attribute. <script type = "text/javascript"> var el = document.createElement("div"); alert(el.getAttribute("id")); alert(el.id); alert(el.hasAttribute("id")); // false el.id = "test"; alert(el.getAttribute("id")); alert(el.id); alert(el.hasAttribute("id")); // true el.id = ""; alert(el.getAttribute("id")); alert(el.id); alert(el.hasAttribute("id")); // true </script> But this looks strange: "Either when an element is created that has an id attribute whose value is not the empty string or when an element's id attribute is set to a value other than the empty string, set the element's ID to the new value." <script type = "text/javascript"> var el = document.createElement("div"); alert(el.getAttribute("id")); alert(el.id); alert(el.hasAttribute("id")); // false el.id = ""; el.setAttribute("id", ""); alert(el.getAttribute("id")); alert(el.id); alert(el.hasAttribute("id")); // true </script> Or maybe create/remove has some other meaning?
And another case: <p id=""></p> <script type = "text/javascript"> alert(document.getElementById("")); // null var el = document.getElementsByTagName("p")[0]; alert(el.getAttribute("id")); alert(el.id); alert(el.hasAttribute("id")); // true </script>
https://github.com/whatwg/dom/commit/967552c81e1912a6ace72050a3a68a257c1ff672
spiritRKS1910 it seems you confuse the attribute with the "ID" concept. <p id=""> has an "id" attribute but does not have an ID.
Yup, I realize about it after submit this examples, but thx for answer, good catch.