开发者

hasAttribute should return true even when the attribute is not explicitly specified, but doesn't

开发者 https://www.devze.com 2023-04-12 23:01 出处:网络
From W3C - hasAttribute - Returns 开发者_如何学编程true when an attribute with a given name is specified on this element or has a default value, false otherwise.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号