最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Weird error: Uncaught TypeError: Object [object HTMLElement] has no method 'getAttribute' - Stack O

programmeradmin0浏览0评论

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?

Share Improve this question asked Jan 14, 2011 at 17:26 KerrickKerrick 7,4788 gold badges41 silver badges46 bronze badges 2
  • 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
Add a ment  | 

2 Answers 2

Reset to default 7

I 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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论