Results 1 to 6 of 6

Thread: Access a CSS class through Javascript

Threaded View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276

    Resolved Access a CSS class through Javascript

    I have a panel (asp.net) with a CSS class that sets the background color. When I click the panel I want to alternate the background color back and forth between two values.

    Then initial bg color in the css:
    Code:
    .panelOpenStyle
    {
    	background-color: #808080;
    }
    The only way I can seem to do it is to hard-code the color values in javascript:
    Code:
    if(document.getElementById('panel1').style.backgroundColor == '#808080')
    		document.getElementById('panel1').style.backgroundColor = '#6699CC';
    	else
    		document.getElementById('panel1').style.backgroundColor = '#808080';
    I would like to use these two CSS classes so I wouldn't have to hard code the values in Javascript:
    Code:
    .panelOpenStyle
    {
    	background-color: #808080;
    }
    
    .panelCloseStyle
    {
    	background-color: #6699cc;
    }
    Is there some way for me to alternate between two CSS classes in javascript?
    Last edited by wey97; Apr 22nd, 2005 at 08:54 AM.

Posting Permissions

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



Click Here to Expand Forum to Full Width