The library for web and native user interfaces.
getDOMNodeID: Don't return .id on random objects
If you defined a global named `id` (a horrible name, I know) then getDOMNodeID(window) would return that object. Since only DOM nodes can have IDs, this should be a noop change otherwise. Test Plan: Verified that document.documentElement and document.body both support getAttributeNode properly in latest Chrome and in IE8.
Ben Alpert committed
Jun 4, 2013 at 19:21 UTC
a9c70bcc1c6c70cad118f0028ced3e532bddb196
1 file changed
+4
-3
src/dom/getDOMNodeID.js
+4
-3
@@ -21,8 +21,9 @@
21
22
/**
23
* Accessing "id" or calling getAttribute('id') on a form element can return its
24
- * control whose name or ID is "id". However, not all DOM nodes support
25
- * `getAttributeNode` (document - which is not a form) so that is checked first.
24
+ * control whose name or ID is "id". All DOM nodes support `getAttributeNode`
25
+ * but this can also get called on other objects so just return '' if we're
26
+ * given something other than a DOM node (such as window).
27
*
28
* @param {DOMElement|DOMWindow|DOMDocument} domNode DOM node.
29
* @returns {string} ID of the supplied `domNode`.
@@ -32,7 +33,7 @@ function getDOMNodeID(domNode) {
33
var attributeNode = domNode.getAttributeNode('id');
34
return attributeNode && attributeNode.value || '';
35
} else {
35
- return domNode.id || '';
36
+ return '';
37
}
38
}
39