Get programming code snippets and tips for HTML, CSS, ASP, SQL, JavaScript, RSS, XML, and more
Lee's Code        A web programmer's toolbox. SEARCH SITE
HOME  |  ABOUT LEE  |  CONTACT  |  SEARCH
Home > Code > JavaScript > Change CSS Property via javaScript

Navigation

Latest Additions

Links


 

Recommendations

Evolve Online
Powered by
Evolve Online
 

Change CSS Property via javaScript

By: Lee A. Shurie
 
Subject: CSS via JavaScript
Language: JavaScript
Rating:
 Rated 13 times. Rate or review this item: 1 2 3 4 5
 Read Reviews
 
Information
Typically, CSS attributes are represented as properties in a style sheet. They may also be coded directly into an html tag. For example: <div Style="font-weight:bold; color:0088dd;">some text here</div>.

But how can you set or change these attributes via JavaScript?

For non hyphenated attributes, the property is identical. So your Javascript could look like this:

onMouseover="this.style.color='#0000ff'"

For hyphenated attributes, drop the hyphen and capitalize the first letter following it. For example: to manipulate the "font-weight" CSS property your JavaScript might look like this:

onMouseover="this.style.fontWeight='#fffff'"

Examples:

color = color
padding = padding
font-weight = fontWeight
background-color = backgroundColor
border-bottom-width = borderBottomWidth
 
Keywords:javascript css style stylesheet
 

Lee's Code programming tips and tricks. Back to top of page.

Programming tips and tricks for ASP, javaScript, SQL, SML, CSS, HTML HOME | ABOUT LEE | CONTACT | SEARCH
 
Copyright © 2001 - 2010 by Lee A. Shurie