Why doesn't Javascript recognize the HTML class attribute?
Posted
by Cornflake
on Stack Overflow
See other posts from Stack Overflow
or by Cornflake
Published on 2010-05-03T22:42:37Z
Indexed on
2010/05/03
22:48 UTC
Read the original article
Hit count: 257
JavaScript
Can anyone help me with a Javascript question, please? Why does the following code display only message boxes with the word "null" in them? And I think there are not enough of them either.
<html>
<head>
<script type="text/javascript">
function showElementClasses(node) {
var els = node.getElementsByTagName("*");
for(var i=0,j=els.length; i<j; i++)
alert(els[i].getAttribute("class"));
alert("Class: " + els[i].className);
}
showElementClasses(document);
</script>
</head>
<body class="bla">
<div class="myclass" style="width: 500; height: 400" id="map"></div>
</body>
</html>
© Stack Overflow or respective owner