faqts : Computers : Internet : Web : CSS : via Scripting

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

6 of 8 people (75%) answered Yes
Recently 4 of 6 people (67%) answered Yes

Entry

How do I access an element's style properties in script

Apr 27th, 2000 20:33
Rey Nuņez, jsWalter,


Inline style information attached to elements is exposed through the 
DOM style object. 
Inline styles are CSS style assignments that an author applies directly 
to individual HTML elements using the style attribute. The style object 
is used to examine these assignments and either make new assignments or 
change existing ones. 
The style object can be set or retrieved by applying the style keyword 
to any valid element object, followed by the corresponding CSS style 
property, as in the following notation. 
To retrieve styles:
cssValue = object.style.cssProperty
To set styles: 
object.style.cssProperty = "cssValue"
The following example sets the font for text in the document body 
to "Verdana." 
document.body.style.fontFamily = "Verdana"
The style object does not give access to the style assignments in style 
sheets. To obtain information about styles in style sheets, you must 
use the DOM styleSheets collection to gain access to the individual 
style sheets defined in the document. 
Note that as of this writing, the style object is supported only in 
IE4+/NN6+.