admin管理员组文章数量:1317565
I get the above error when I run this line of JavaScript (And thisMaxNode holds an HTML Element object with an attribute of data-max="10"
or another number):
var thisMax = parseFloat(thisMaxNode.getAttribute('data-max'));
Isn't the HTMLElement
object exactly what should have the method getAttribute
?
I get the above error when I run this line of JavaScript (And thisMaxNode holds an HTML Element object with an attribute of data-max="10"
or another number):
var thisMax = parseFloat(thisMaxNode.getAttribute('data-max'));
Isn't the HTMLElement
object exactly what should have the method getAttribute
?
-
Since 'data-max' is not a standard HTML attribute, it raises the question, what kind of HTML Element is
thisMaxNode
? – Dancrumb Commented Jan 14, 2011 at 17:30 -
1
@Dancrumb:
data-
attributes are a feature of HTML5, and would be a custom attribute in HTML4. ejohn/blog/html-5-data-attributes – user113716 Commented Jan 14, 2011 at 17:32
2 Answers
Reset to default 7I wonder if thisMaxNode actually contains an array of one HTML Element. Array, of course, doesn't have a getAttribute method.
I think you're assuming too much. Take a step back and start confirming things.
What does alert( thisMaxNode.nodeType )
give you? 1
? If not, it's not an element node and perhaps a nodeList or a whitespace node... more code would help.
本文标签:
版权声明:本文标题:javascript - Weird error: Uncaught TypeError: Object [object HTMLElement] has no method 'getAttribute' - Stack O 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742022247a2414891.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论