Email conversation
From | Michael Cummings |
To | Me |
Subject | getAttribute('style') in IE7 returning [object] instead of string value |
Date | 19 August 2007 01:14 |
Outstanding site and you certainly have a gifted mind! I was curious if you
had encountered this issue before. IE7 does not seem to understand the
getAttribute method when applied to inline-style whereas it understands
getAttribute perfectly well for other attributes (such as name). The
following html is a minimalist illustration of the problem.
<html>
<head>
<title>GetAttribute Test</title>
<script type="text/javascript">
function viewStyleAttr()
{
alert(document.getElementById('myDiv').getAttribute('style'))
}
</script>
</head>
<body>
<div id="myDiv" style="color: red">TESTING</div>
<input type="button" value="Get Style Attribute" onclick="viewStyleAttr()"
/>
</body>
</html>
Firefox will alert the value: "color: red" (....like its supposed to)
IE7 will alert the value: "[object]"
In the context of what I am trying to develop, this is a huge problem. Any
help would be greatly appreciated.
Thanks so much for the great ECMAScript reference!
-Mike
From | Me |
To | Michael Cummings |
Subject | Re: getAttribute('style') in IE7 returning [object] instead of string value |
Date | 22 August 2007 08:31 |
Michael,
> IE7 does not seem to
> understand the getAttribute method when applied to inline-style
http://www.howtocreate.co.uk/tutorials/javascript/dombasics
"Many browsers will have trouble retrieving values for style and class, as
well as event handlers."
Use .style for style attributes, .className for class attributes, and .onfoo
for event handlers. Do not use .getAttribute for these.
Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/