dvtng / jss

JavaScript library for getting and setting CSS stylesheet rules
335 stars 54 forks source link

Error in Chrome when using linked css file #15

Closed amtivey closed 11 years ago

amtivey commented 11 years ago

The following error is raised when linking css : Uncaught TypeError: Cannot read property 'length' of null

Test with the following code:

HTML

<html>
    <head>
        <title>rule test</title>
        <link rel="stylesheet" type="text/css" href="rule.css">
        <script type="text/javascript" src="jss.js"></script>
        <script>
            function test(rule) {
                var str = jss(rule).get();
                jss(rule, { color: 'blue' });
            }
        </script>
        <style>
            .rule-test-local { color: green; }
        </style>
    </head>
    <body>
        <div class="rule-test-link" onclick="test('.rule-test-link');">test linked css</div>
        <div class="rule-test-local" onclick="test('.rule-test-local');">test local css</div>
    </body>
</html>

CSS

.rule-test-link { color: red; }
matthijsgroen commented 11 years ago

I ran into this error aswell..

somehow

setTimeout(function() { jss(rule, { color: 'blue' }); }); 

fixed it for me

amtivey commented 11 years ago

Since this is a known bug in chrome (https://code.google.com/p/chromium/issues/detail?id=49001) I am closing this issue.

Thanks for the suggestion Matt :)