views:

563

answers:

1

In IE with document.getElementById("css_id").styleSheet

or in Firefox document.getElementById("css_id").sheet

I've a style sheet object to manipulate but in Chrome and Safari browser that property there is not.

How can I get that object?

Thanks

+2  A: 

Errr, in my tests .sheet works fine -- my testcase was

<html>
<head>
    <style id="styleElement"></style>
    <link id="linkElement" data="data:text/css," rel="stylesheet"></link>
    <script>
        window.onload=function() {
            alert(["<style element>.style: " + document.getElementById('styleElement').sheet,
                   "<link element>.style: " + document.getElementById('linkElement').sheet])
        }
    </script>
</head>
</html>

I only tested in Safari 3.2 and the WebKit nightlies, Chrome just uses the WebKit from Safari 3.1 but i don't believe there's any engine changes between 3.1 and 3.2.

olliej
I'm appending at run-time via appendChild a link tag and after I tryto load it via getElementById but it seems as the css file is not loaded yet... and so it returns null. Strange behavior ...
xdevel2000
...ah again strange... if I try to get the CSS via document.styleSheetsit is returned!
xdevel2000
@xdevel2000: If you have a test case where Safari behaves differently from Firefox and IE, you should file a report at http://bugs.webkit.org
olliej