using JavaScript to rewrite CSS rules

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

    #1

    using JavaScript to rewrite CSS rules

    I am trying to make a javascript function that can rewrite javascript
    rules dynamically (no, not the style tag of an individual element, but
    the actual rule in the <head> portion of the document).

    I have this code working in Mozilla (so I imagine Netscape browsers)
    but it gives me an error with IE. A few questions about it:

    First, here is my current code:
    <code>
    function expand(show)
    {
    for(var i=1;i<=linkNum; i++)
    {
    if(show == i)) document.styleS heets[0].cssRules[i].style.visibili ty="visible";
    else document.styleS heets[0].cssRules[i].style.visibili ty="hidden";
    }
    }
    </code>

    As I said, this works in Moz, but not in IE. How do i handle this??

    And my next question, instead of having to access each rule by its
    index in an array of the stylesheet, is there a way I can access it by
    name (so instead of doing cssRules[0], i could do.Rule("body") or
    something with a similar function?)

    I am trying to do some work with more advanced DHTML and am running
    into even more IE specfic code it seems. Thanks for the help.
  • Martin Honnen

    #2
    Re: using JavaScript to rewrite CSS rules



    jbj wrote:
    [color=blue]
    > I am trying to make a javascript function that can rewrite javascript
    > rules dynamically (no, not the style tag of an individual element, but
    > the actual rule in the <head> portion of the document).
    >
    > I have this code working in Mozilla (so I imagine Netscape browsers)
    > but it gives me an error with IE. A few questions about it:
    >
    > First, here is my current code:
    > <code>
    > function expand(show)
    > {
    > for(var i=1;i<=linkNum; i++)
    > {
    > if(show == i)) document.styleS heets[0].cssRules[i].style.visibili ty="visible";
    > else document.styleS heets[0].cssRules[i].style.visibili ty="hidden";
    > }
    > }
    > </code>
    >
    > As I said, this works in Moz, but not in IE. How do i handle this??[/color]

    IE has its own API, with IE you need e.g.
    document.styleS heets[0].rules[1].style.cssPrope rtyName = ...
    [color=blue]
    > And my next question, instead of having to access each rule by its
    > index in an array of the stylesheet, is there a way I can access it by
    > name (so instead of doing cssRules[0], i could do.Rule("body") or
    > something with a similar function?)[/color]

    You can check the selectorText property of a rule.

    --

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

    Comment

    Working...