I tried to print the list of attributes values in a specific CSS class with the getElementsByClassName method like below :
<html>
<head>
<style>
.toto {
width:200px;
height:50px;
background-color:red;
}
</style>
</head>
<body>
<div id="lol" class="toto"></div>
<script language="javascript" type="text/javascript">
var toto = document.getElementsByClassName('toto');
if (toto) {
for (int i; i < toto.length; i++)
document.write(toto[i]);
}
</script>
</body>
</html>
But toto.length = 1 in all cases. I would like to print the values '200px', '50px' et 'red'. Does anyone can help me ? Thanks a lot in advance for your help.
getElementsByClassName
returns the DOM elements with said class (and there is only one). It does not let you access the CSS rules of that class. For a solution, have a look at the bottom of this answer. – Yellowknife