Const isAttr
isAttr: function = // We check that ``attrNodeType`` is not undefined because eventually// ``ATTRIBUTE_NODE`` will be removed from the ``Node`` interface, and then we// could be testing ``undefined === undefined`` for objects which are not// attributes, which would return ``true``. The function is not very strict// but it should not be too lax either.(attrNodeType === undefined) ? isAttrNoType : isAttrWithType
Type declaration
-
- (it: Attr | Node | null | undefined): boolean
-
Parameters
-
it: Attr | Node | null | undefined
Returns boolean
Determines whether the thing passed is an attribute. This function does not try to be strict about what is passed to it. Pass anything that has a
nodeType
field with a value equal toNode.ATTRIBUTE_NODE
and it will returntrue
, even if the thing is not actually an attribute.This is needed because wed works with HTML and XML DOM trees and unfortunately, things have gotten murky. Once upon a time, an attribute was determined by checking the
nodeType
field. This worked both for HTML and XML nodes. This worked because attributes inherited fromNode
, which is the DOM interface that definesnodeType
. It was paradise.Then the luminaries that drive the implementation of DOM in actual browsers decided that attributes were no longer really nodes. So they decided to make attribute objects inherit from the
Attr
interface only. This means thatnodeType
no longer exists for attributes. The new way to test whether something is an attribute is to test withinstanceof Attr
. However, as usual, the DOM implementation for XML lags behind the HTML side and on Chrome 49 (to name just one case),instanceof Attr
does not work on XML attributes whereas testingnodeType
does.This function performs a test that works on HTML attributes and XML attributes.
The thing to test.
true
if an attribute,false
if not.