Merge pull request #61 from spicyj/getdomnodeid

getDOMNodeID: Don't return .id on random objects
This commit is contained in:
Timothy Yung
2013-06-14 11:27:44 -07:00
+4 -3
View File
@@ -21,8 +21,9 @@
/**
* Accessing "id" or calling getAttribute('id') on a form element can return its
* control whose name or ID is "id". However, not all DOM nodes support
* `getAttributeNode` (document - which is not a form) so that is checked first.
* control whose name or ID is "id". All DOM nodes support `getAttributeNode`
* but this can also get called on other objects so just return '' if we're
* given something other than a DOM node (such as window).
*
* @param {DOMElement|DOMWindow|DOMDocument} domNode DOM node.
* @returns {string} ID of the supplied `domNode`.
@@ -32,7 +33,7 @@ function getDOMNodeID(domNode) {
var attributeNode = domNode.getAttributeNode('id');
return attributeNode && attributeNode.value || '';
} else {
return domNode.id || '';
return '';
}
}