I have this very simple HTML page, and I'm trying to get the CSSRules of #poulet, but when I'm accessing the documents.styleSheets[0].cssRules I get this error in Chrome v5.0.375.55:
Uncaught TypeError: Cannot read property 'length' of null
Here is what my code looks like:
HTML FILE
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="css/test.css" type="text/css" />
<script type="text/javascript" src="js/test.js"></script>
<title>Mozilla</title>
<script>
window.onload = function(){
var test = findKeyframesRule('poulet');
alert(test);
}
</script>
</head>
<body>
<div id="poulet">
allo
</div>
</body>
</html>
JS FILE
function findKeyframesRule(rule)
{
var ss = document.styleSheets;
for (var i = 0; i < ss.length; ++i)
{
for (var j = 0; j < ss[i].cssRules.length; ++j)
{
if (ss[i].cssRules[j].type == window.CSSRule.WEBKIT_KEYFRAMES_RULE && ss[i].cssRules[j].name == rule)
return ss[i].cssRules[j];
}
}
return null;
}
CSS FILE
html, body {
background: #cccccc;
}
#poulet{
border: 10px solid pink;
}
The files can be found here. I really need help on this one, please!!! D: