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 25704 - "When an element's id attribute is removed, unse..."
Summary: "When an element's id attribute is removed, unse..."
Status: RESOLVED FIXED
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: DOM (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Anne
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-05-14 08:04 UTC by Simon Pieters
Modified: 2014-05-14 13:11 UTC (History)
3 users (show)

See Also:


Attachments

Description Simon Pieters 2014-05-14 08:04:45 UTC
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?
Comment 1 Arkadiusz Michalski (Spirit) 2014-05-14 09:55:28 UTC
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?
Comment 2 Arkadiusz Michalski (Spirit) 2014-05-14 10:10:31 UTC
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>
Comment 4 Simon Pieters 2014-05-14 13:08:55 UTC
spiritRKS1910 it seems you confuse the attribute with the "ID" concept. <p id=""> has an "id" attribute but does not have an ID.
Comment 5 Arkadiusz Michalski (Spirit) 2014-05-14 13:11:19 UTC
Yup, I realize about it after submit this examples, but thx for answer, good catch.