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.