class attribute | className property (Internet Explorer)

Switch View :
ScriptFree
class attribute | className property

[This documentation is preliminary and is subject to change.]

Sets or retrieves the class of the object.

Syntax

HTML<element class="p" ... >
JavaScript

p = object.className

Property values

Type: String

the class or style rule.

Remarks

The class is typically used to associate a particular style rule in a style sheet with the element.

You can apply multiple styles to an element by specifying more than one style for the CLASS attribute. To apply multiple styles to a single element, use the following syntax:


<ELEMENT CLASS = "sClass [ sClass2 [ sClass3 ... ] ]" ... >

By default, the property is equal to the string assigned to the className property of the given object, or null if the attribute is not explicitly assigned.

When multiple styles are specified for an element, a conflict could develop if two or more styles define the same attribute differently. In this case, you can resolve the conflict by applying styles to the element in the following order, according to the Cascading Style Sheets (CSS) selector used to define the style:

  1. Element
  2. CLASS
  3. ID
  4. Inline styles

When two or more selectors pertain to an element, a style defined later takes precedence over a style defined earlier. For more information, see Introduction to Cascading Style Sheets.

Multiple styles are supported as of Microsoft Internet Explorer 5.

In Windows Internet Explorer 8, class names, such as hslice and entry-title, are used to identify portions of a webpage that can be monitored for updates (Web Slices). For more information, see Subscribing to Content with Web Slices.

Examples

This example uses the className attribute to apply one or more styles to an HTML element.

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/className.htm


<HEAD>
    <STYLE TYPE="text/css">
        P {font-size: 24pt;}
        .redText {color: red;}
        .blueText {color: blue;}
        .italicText {font-style: italic;}
    </STYLE>
</HEAD>

<BODY>
    <P>
        Large text, no class specified, one implied.
    </P>
    <P CLASS="redText">
        Large text, .redText class specified.
    </P>
    <P CLASS="blueText italicText">
        Large text, .blueText and .italicText classes specified.
    </P>
</BODY>

 

 

Build date: 3/8/2012

Community Content

Stanley Roark
Caution - multiple Classes - quote, no Persistence
1. sClass string must be Quoted/semiquoted on multiple Classes: eg. <DIV CLASS='a b c'...
(Have-yet to try multiple Attributes as CSS-selectors)

2. N.B. Persistence behaviors (history, snapshot, favorite) DO NOT COMBINE in Class-use nor Class-Style-definition.
(Class, -not Attribute,- is sufficient for Persistence)