Accessing stylesheets from javascript

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

    Accessing stylesheets from javascript

    I'm looking for a way to do:

    function resetBorder(the Obj) {
    theObj.style.bo rder = theObj.class.bo rder;
    }

    But it doesn't seem to be as simple as that :)
    I'd like a cross-browser solution, but will settle for IE.

    Love some help!
    Cheers
    Rick
  • Martin Honnen

    #2
    Re: Accessing stylesheets from javascript



    Rick Measham wrote:
    [color=blue]
    > I'm looking for a way to do:
    >
    > function resetBorder(the Obj) {
    > theObj.style.bo rder = theObj.class.bo rder;
    > }
    >
    > But it doesn't seem to be as simple as that :)
    > I'd like a cross-browser solution, but will settle for IE.[/color]

    I am not sure what
    theObj.class.bo rder
    is supposed to yield but I suspect you want to reset the inline style so
    that any existing style sheet takes over. The right way to achieve that
    is with
    theObj.style.bo rder = '';
    as that clears the inline style and then the stylesheet kicks in.
    Should work with IE4+, Netscape 6+, Opera 7.
    --

    Martin Honnen


    Comment

    • RIck Measham

      #3
      Re: Accessing stylesheets from javascript

      Martin Honnen wrote:[color=blue]
      >
      > Rick Measham wrote:
      >[color=green]
      >> I'm looking for a way to do:
      >>
      >> function resetBorder(the Obj) {
      >> theObj.style.bo rder = theObj.class.bo rder;
      >> }
      >>
      >> But it doesn't seem to be as simple as that :)
      >> I'd like a cross-browser solution, but will settle for IE.[/color]
      >
      > I am not sure what
      > theObj.class.bo rder
      > is supposed to yield but I suspect you want to reset the inline style so
      > that any existing style sheet takes over. The right way to achieve that
      > is with
      > theObj.style.bo rder = '';
      > as that clears the inline style and then the stylesheet kicks in.
      > Should work with IE4+, Netscape 6+, Opera 7.[/color]

      That's what I'm trying to do, and it works with IE5 for Mac. However IE6 for
      Win thinks that theObj.style.bo rder='' is the same as no border. So what I
      wanted to do was access the border property of the class assigned to the
      object and apply said border as a style.

      --
      Obviously the reply-to is a fake. Just change the 'spam-' to 'i' so that the
      result sounds like why you go to an optometerist.

      Comment

      • DB McGee

        #4
        Re: Accessing stylesheets from javascript

        "RIck Measham" <rickm@spam-site.net.au> wrote in message
        news:3faa4797$0 $3499$afc38c87@ news.optusnet.c om.au...[color=blue]
        > Martin Honnen wrote:[color=green]
        > >
        > > Rick Measham wrote:
        > >[color=darkred]
        > >> I'm looking for a way to do:
        > >>
        > >> function resetBorder(the Obj) {
        > >> theObj.style.bo rder = theObj.class.bo rder;
        > >> }
        > >>
        > >> But it doesn't seem to be as simple as that :)
        > >> I'd like a cross-browser solution, but will settle for IE.[/color]
        > >
        > > I am not sure what
        > > theObj.class.bo rder
        > > is supposed to yield but I suspect you want to reset the inline style so
        > > that any existing style sheet takes over. The right way to achieve that
        > > is with
        > > theObj.style.bo rder = '';
        > > as that clears the inline style and then the stylesheet kicks in.
        > > Should work with IE4+, Netscape 6+, Opera 7.[/color]
        >
        > That's what I'm trying to do, and it works with IE5 for Mac. However IE6[/color]
        for[color=blue]
        > Win thinks that theObj.style.bo rder='' is the same as no border. So what I
        > wanted to do was access the border property of the class assigned to the
        > object and apply said border as a style.[/color]


        Re: theObj.class.bo rder

        Is 'border' a CSS class name? If so you can simply rewrite as follows:

        theObj.classNam e = 'border'

        Or, you can simply reapply the className originally assigned to the object
        (assuming that you've subsequently modified 'theObj.style' properties).




        Comment

        Working...