#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2002
    Posts
    5
    Rep Power
    0

    Question Changing a style with Javascript


    How do you change the background color of a specific style in a stylesheet? I have a style named "navH" and when the user clicks a link the style changes so all the objects on the page that have that style assigned change. How can I do this?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Nov 2001
    Posts
    1,882
    Rep Power
    19
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2002
    Posts
    5
    Rep Power
    0
    No that's not really what I need. I'm looking for something more like this:

    function changeColors(color) {
    document.all.navH.background-color=color
    }

    Something like that. It will change the style and therefore all the elements with that class.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Nov 2001
    Posts
    1,882
    Rep Power
    19
    document.all.### refers to an ID.
    A CSS class is not an ID.
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2002
    Posts
    5
    Rep Power
    0
    So what should I use?
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2001
    Posts
    765
    Rep Power
    13
    You can change specific attributes of a declared style class on your page, but it's not as easy as changing the class of individual elements. Here's a hint:

    http://www.faqts.com/knowledge_base/...d/2147/fid/128

IMN logo majestic logo threadwatch logo seochat tools logo