Michael Cummings

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromMichael Cummings
ToMe
SubjectgetAttribute('style') in IE7 returning [object] instead of string value
Date19 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
FromMe
ToMichael Cummings
SubjectRe: getAttribute('style') in IE7 returning [object] instead of string value
Date22 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/
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.