retriving property from style sheet

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • alex bazan

    #1

    retriving property from style sheet

    Is it possible to retrieve a property from a defined style in a style sheet?

    for example, if i have:

    <style>
    .mystyle {background-color:#ff0000}
    </style>

    how can retrieve the background color for that style?

    is there something like: document.mystyl e.background-color (?)

    thanks in advance.
    alex.
  • Martin Honnen

    #2
    Re: retriving property from style sheet



    alex bazan wrote:
    [color=blue]
    > Is it possible to retrieve a property from a defined style in a style
    > sheet?
    >
    > for example, if i have:
    >
    > <style>
    > .mystyle {background-color:#ff0000}
    > </style>
    >
    > how can retrieve the background color for that style?[/color]

    In Netscape 6 and later, Mozilla, IE 4 and later there is a property
    document.styleS heets
    thus if you have exactly one embedded CSS stylesheet
    <style type="text/css">
    .mystyle {background-color:#ff0000}
    </style>
    you can access it as
    var stylesheet = document.styleS heets ? document.styleS heets[0] : null;
    then in Mozilla and other W3C DOM compliant browsers each sheet has a
    property cssRules for the rules, in IE there is a property rules e.g.
    if (stylesheet) {
    var rules = stylesheet.cssR ules ? stylesheet.cssR ules :
    stylesheet.rule s;
    the first (and only rule in your example) has the index 0 e.g.
    if (rules && rules[0]) {
    rules[0].style.backgrou ndColor = '#00ff00';
    }
    }

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/

    Comment

    • alex bazan

      #3
      Re: retriving property from style sheet

      En/na Martin Honnen ha escrit:[color=blue]
      >
      >
      >
      > In Netscape 6 and later, Mozilla, IE 4 and later there is a property
      > document.styleS heets[/color]

      Thanks, finally i got the right "googlequer y" and found a script with a
      similar code
      (http://chapnickman.com/2005/03/14/ge...th-javascript/)

      At last, i opted for a PHP solution.
      thaks for all.
      alex.

      Comment

      Working...