Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jan 2003
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb Does the CSS style sheet belong to the DOM

    If so... how can I build a list of available styles?

    I'm creating (extending) a DHTML rich text editor...

    Thanks!

  • #2
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    What exactly do you mean?

    document.styleSheets is a StyleSheetList which has all the StyleSheets in the document, collected from <?xml-stylesheet?>, or <link/> and <style>.

    You can then use DOM2 CSS you grab all selectors, or rules, or whatever. Perhaps you should explain a little but further?

  • #3
    New to the CF scene
    Join Date
    Jan 2003
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, you gave me just enough input...

    What I wanted to do was something like this:

    PHP Code:
    <script language="JavaScript">
    <!--
    with (document.styleSheets[0])
        {
            for (
    i=0;i<rules.length;i++)
                {
                    
    alert(rules.item(i).selectorText);
                }
        }
    //-->
    </script> 
    I'll take it from here!

    (PS the above code is not PHP, but at least it looks fancy )

  • #4
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    You can make that DOM-compliant by using the cssRules collection instead of the IE-only rules collection.

    PHP Code:
    <script language="JavaScript">

    <!--

    with (document.styleSheets.item(0))

        {
            var 
    rls cssRules || rules;

            for (
    i=0;i<rls.length;i++)

                {

                    
    alert(rules.item(i).selectorText);

                }

        }

    //-->

    </script> 
    Now that is DOM2 compliant (so it'll work in NS6+), and also functions in IE with that single shortcircuit workaround.

  • #5
    New to the CF scene
    Join Date
    Jan 2003
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks!!

    Although I hardly get any NS* clients to my sites...

  • #6
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    Originally posted by webwarrior
    Thanks!!

    Although I hardly get any NS* clients to my sites...
    Well, this means that it'll work in NS6+, Konqueror and Safari (I believe KHTML does DOM2 Style... I'll have to check), and all future compliant browsers. It basically just guarentees you won't need to rewrite it for each new browser generation.

    There are long-term benefits to writing DOM-compliant code, such as this.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •