hasAttribute should return true even when the attribute is not explicitly specified, but doesn't
From W3C - hasAttribute - Returns 开发者_如何学编程true when an attribute with a given name is specified on this element or has a default value, false otherwise.
Now, all elements have a default class attribute as an empty string as mentioned here
So, if I apply hasAttribute('class')
or hasAttribute('className')
on an element on which I haven't explicitly specified the class attribute, it should even then return true, but it doesn't in Firefox and Chrome. Why is this happening ?
This is happening because of:
"However, empty default attributes do not appear in the DOM tree — only those attributes which have an actual value (either a specific default value in the DTD, or an explicit value) appear in the DOM; this is referred to as having an effective value. "
you can read it here
精彩评论