admin管理员组

文章数量:1317123

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.

本文标签: