Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change CSS properties with getElementById

Status
Not open for further replies.

Niavlys

IS-IT--Management
Jun 3, 2002
197
0
0
CA
Hi,
I have this in my CSS page :

Code:
#School li a:active 
{ 
  color: #FFFFFF; 
  background: url(images/schoolmenu.gif) 0 -64px; 
  padding: 8px 0 0 10px; 
}

which I want to change the color onClick.
How do I access the color element using getElementById?
document.getElementbyId('School')...

Thanks.
 

You can take any CSS property (pretty much) and do the same thing... in the event of the property being hyphenated (ie: background-color) you remove the hyphen and capitalise the next character (ie: backgroundColor). Remembering all the time that javascript is case sensitive.

If you can remember that simple technique, then you will never need to ask how to use javascript to fiddle with CSS interactively again!

Cheers,
Jeff

 
Note, you're changing the inline style of the particular element. You're NOT changing the CSS declaration itself, so anything else with that class assigned is not changed.

That's a good thing, but it confused me when I was learning, so I thought I'd point it out.

Thomas D. Greer

Providing PostScript & PDF
Training, Development & Consulting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top