Book HomeMac OS X for Unix GeeksSearch this book

Chapter 25. W3C DOM Reference

This part of the book is a reference section that documents the interfaces, methods, and properties defined by the W3C Level 1 and Level 2 DOM standards. Intermediate and advanced programmers who are writing for the newest generation of standards-compliant web browsers will use this reference section, in conjunction with the core and client-side JavaScript references in Part III and Part IV. The introduction and sample reference page explain how to use and get the most out of this reference section. There are significant differences between this reference section and the other two, and you should read this introduction carefully so you can fully understand the reference information it contains.

Like the core and client-side references, this reference section is arranged alphabetically. The reference pages for the methods and properties of DOM interfaces are alphabetized by their full names, which include the names of the interfaces that define them. For example, if you want to read about the appendChild( ) method of the Node interface, you would look under "Node.appendChild," not just "appendChild."

To save space in this enlarged fourth edition of the book, properties in this reference section do not have reference pages of their own (all interfaces and methods do have their own reference pages, however). Instead, each property is completely documented in the reference page for the interface that defines it. For example, you can read about the tagName property of the Element interface in the "Element" reference page.

Sometimes you may find that you don't know the name of the interface that defines the method or property you want to look up, or you may not be sure which of the three reference sections to look up a class or interface in. Part VI of this book is a special index designed to help with these situations. Look up the name of a class, interface, method, or property, and it will tell you which reference section to look in and which class to look under in that section. For example, if you look up "Document," it will tell you that both the client-side and DOM reference sections have entries under that name. And if you look up the name "firstChild," it will tell you that firstChild is a property of Node, which you can read about in this DOM reference section.

Once you've found the reference page you're looking for, you shouldn't have much difficulty finding the information you need. Because the DOM standard is intended to work with languages other than JavaScript, however, it was written with typed languages (such as Java and C++) in mind. Although JavaScript is an untyped language, the property and method type information defined by the standard is still quite useful and is included in the reference pages in this section. This means that method and property synopses in this section use a syntax that is more like Java than like JavaScript. What follows is a sample reference page titled "Sample Entry" that demonstrates the structure of each reference page and explains how to interpret the information presented in each section. Even if you are already well familiar with the third edition of this book, take the time to read this page before diving into the DOM reference section.

Sample Entryhow to read DOM reference pages

Availability

Availability

Inherits from/Overrides

Inherits from

Title and Short Description

Every reference entry begins with a title block like that above. The entries are alphabetized by title. The short description, shown next to the title, gives you a quick summary of the item documented in the entry; it can help you quickly decide if you're interested in reading the rest of the page.

Availability

The information in the "Availability" section tells you what level and what module of the DOM standard defines the interface or method. Since properties do not have their own reference pages, they do not have availability information. If the availability of a property is different from the availability of the interface that defines it, this fact is noted in the description of the property.

Inherits from

DOM interfaces can inherit properties and methods from other interfaces. If a DOM interface inherits from another interface, the inheritance hierarchy is shown in the "Inherits from" section. For example, the "Inherits from" information for the HTMLElement interface looks like this:

Node Figure Element Figure HTMLElement

This indicates that HTMLElement inherits from the Element interface, which in turn inherits from the Node interface. When you see this section, you may also want to look up the other listed interfaces.

Subinterfaces

This section contains the opposite of the "Inherits from" information: it lists any interfaces that inherit from this one. For example, the "Subinterfaces" section of the reference page for the Element interface specifies that HTMLElement is a subinterface of Element and inherits Element's methods and properties.

Also Implements

The modular structure of the DOM standard means that some interfaces have been broken into multiple separate interfaces, so that implementations have to implement only the interfaces that are part of the modules they support. It is common for an object that implements one interface (such as Document) to also implement several other simple interfaces (such as DocumentCSS, DocumentEvent, and DocumentViews) that provide functionality specific to other modules. When an interface has minor interfaces that are intended to be implemented along with it, those minor interfaces are listed in this section.

Constants

Some DOM interfaces define a set of constants that serve as the values for a property or as the arguments to a method of that interface. The Node interface, for example, defines important constants to serve as the set of legal values for the nodeType property of all Document nodes. When an interface defines constants, they are listed and documented in this section. The listings include the type, the name, and the value (in that order) of each constant. See the Section section for a discussion of the syntax used in these listings. Note that constants are static properties of the interface itself, not of instances of that interface.

Properties

If the reference page documents an interface, this section lists and documents the properties defined by that interface. Each entry in the list specifies the name and type of the property and may also include other keywords that provide additional information about the property. Note that in this Java-style syntax, the name of the property comes last, and all the information that precedes the name provides type and other information about the property. For example, the HTMLTableElement and HTMLTableCellElement interfaces define properties that include the following:

HTMLTableCaptionElement caption
The caption property. It refers to an object of type HTMLTableCaptionElement.

readonly HTMLCollection rows
The rows property. It refers to an HTMLCollection object and is read-only: you can query the value of the property, but you cannot set it.

deprecated String align
The align property. It is a string, but it is deprecated and its use is discouraged.

readonly long cellIndex
The cellIndex property. It is a long integer value (see the Section section) and is read-only.

Methods

If the reference page documents an interface, this section lists the names of the interface's methods and provides a short description of each. Full documentation for each method is found in a separate reference page.

Synopsis

If the reference page documents a method, this section presents the method signature or synopsis. This section uses a Java-style syntax to specify (in order):

For example, the "Synopsis" section of the Node.insertBefore( ) method looks like this:

Node insertBefore(Node newChild, 
                  Node refChild)
    throws DOMException;

You can glean the following information from this synopsis: the name of the method is "insertBefore"; it returns a Node object; the first argument is a Node object and specifies the "newChild" (presumably the one to be inserted); the second argument is also a Node object and specifies the "refChild" (presumably the node before which the other is inserted); and the method may, in some circumstances, throw an exception of type DOMException.

The subsections that follow the synopsis provide additional information about the arguments, return value, and exceptions of the method. See also the Section section for more information about the Java-style syntax used here to specify the types of method arguments.

Arguments

If a method has arguments, the "Synopsis" section is followed by an "Arguments" subsection that lists the names of the arguments and describes each one. Note that argument names are listed in italics, to indicate that they are not to be typed literally but instead represent some other value or JavaScript expression. To continue with the previous example, the "Arguments" section of Node.insertBefore( ) looks like this:

newChild
The node to be inserted into the tree. If it is a DocumentFragment, its children are inserted instead.

refChild
The child of this node before which newChild is to be inserted. If this argument is null, newChild is inserted as the last child of this node.

Returns

The "Synopsis" section specifies the data type of the method's return value, and the "Returns" subsection provides additional information. If the method has no return value (i.e., if it is listed in the "Synopsis" section as returning void), this section is omitted.

Throws

This section explains the kinds of exceptions the method can throw and under what circumstances it throws them.

DOM Types

DOM reference pages use a Java-style syntax for specifying the types of constants, properties, method return values, and method arguments. This section provides more information about that syntax. Note that the reference pages themselves do not have "DOM Types" sections!

The general syntax is:

modifiers type name

The name of the constant, property, method, or method argument always comes last and is preceded by type and other information. The modifiers used in this reference section (note that these are not actually legal Java modifiers) are:

readonly
Specifies that a property value can be queried but cannot be set.

deprecated
Specifies that a property is deprecated and its use should be avoided.

unsigned
Specifies that a numeric constant, property, return value, or method argument is unsigned; i.e., it may be zero or positive, but may not be negative.

The types of DOM constants, properties, method return values, and method arguments do not always correspond directly to the types supported by JavaScript. For example, some properties have a type of short which specifies a 16-bit integer. Although JavaScript only has a single numeric type, this reference section uses the DOM type simply because it provides more information about what range of numbers are legal. The DOM types you will encounter in this reference section are:

String
A core JavaScript String object.

Date
A core JavaScript Date object (this is not commonly used).

boolean
A boolean value: true or false.

short
A short (16-bit) integer. This type may have the unsigned modifier applied to it.

long
A long (64-bit) integer. This type may have the unsigned modifier applied to it.

float
A floating-point number. This type may not have the unsigned modifier applied to it.

void
This type is used for method return values only; it indicates that the method does not return any value.

Any other type
Any other types you see in this reference section are names of other DOM interfaces (for example, Document, DOMImplementation, Element, HTMLTableElement, and Node).

Description

Most reference pages contain a "Description" section, which is the basic description of the interface or method that is being documented. This is the heart of the reference page. If you are learning about an interface or method for the first time, you may want to skip directly to this section and then go back and look at previous sections such as "Synopsis," "Properties," and "Methods." If you are already familiar with an interface or method, you probably won't need to read this section and instead will just want to quickly look up some specific bit of information (such as the name of a property or the type of an argument from the "Properties" or "Arguments" sections).

In some pages, this section is no more than a short paragraph. In others, it may occupy a page or more. For some simple methods, the "Arguments," "Returns," and "Throws" sections document the method sufficiently by themselves, so the "Description" section is omitted.

Example

Reference pages for some commonly used interfaces and methods include an example in this section to illustrate typical usage of the interface or method. Most pages do not contain examples, however -- you'll find those in first half of this book.

See Also

Most reference pages conclude with cross-references to related reference pages that may be of interest. Most of these cross-references are to other reference pages in this DOM reference section. Some are to individual property descriptions contained within an interface reference page, however, and others are to related reference pages in the client-side reference section or to chapters in the first two parts of the book.

Reference pages that document interfaces (but not those that document methods) may have additional paragraphs at the end of the "See Also" section. These are cross-references that show how the interface is used. A "Type of" paragraph lists properties whose values are objects that implement the interface. A "Passed to" paragraph lists methods that take an argument that implements the interface. A "Returned by" paragraph lists methods that return an object that implements the interface. These cross-references show how you can obtain an object of this interface and what you can do with it once you have obtained it.

AbstractViewa window displaying a document

Availability

DOM Level 2 Views

Also Implements

ViewCSS
If the DOM implementation supports the CSS module, any object that implements the AbstractView interface also implements the ViewCSS interface. For convenience, the method defined by the ViewCSS interface is listed under "Methods."

Properties

readonly Document document
The Document object that is displayed by this View object. This Document object also implements the DocumentView interface.

Methods

getComputedStyle( ) [DOM Level 2 CSS]
This ViewCSS method returns a read-only CSSStyleDeclaration that represents the computed style information for a specific document element.

Description

In the DOM, a view is an object that displays a document in some way. The Window object of client-side JavaScript is such a view. This AbstractView interface is a very preliminary step toward standardizing some of the properties and methods of the Window object. It simply specifies that all View objects have a property named document that refers to the document they display. In addition, if an implementation supports CSS style sheets, all View objects also implement the ViewCSS interface and define a getComputedStyle( ) method for determining how an element is actually rendered in the view.

The document property gives every view a reference to the document it displays. The reverse is true also: every document has a reference to the view that displays it. If a DOM implementation supports the View module, the object that implements the Document interface also implements the DocumentView interface. This DocumentView interface defines a defaultView property that refers to the window in which the document is displayed.

This interface has the word "Abstract" in its name to emphasize the fact that it is merely the beginning of a standardized window interface. In order to be useful, future levels of the DOM standard will have to introduce a new interface that extends AbstractView and adds other properties or methods.

See Also

Reference

Type of

Document.defaultView

AbstractView.getComputedStyle( )retrieve the CSS styles used to render an element

Availability

DOM Level 2 CSS

Synopsis

CSSStyleDeclaration getComputedStyle(Element elt, 
                                     String pseudoElt);

Arguments

elt
The document element whose style information is desired.

pseudoElt
The CSS pseudoelement, or null if there is none.

Returns

A read-only CSSStyleDeclaration object (which typically also implements the CSS2Properties interface) that specifies the style information used to render the specified element in this view. Any length values queried from this object are always absolute or pixel values, not relative or percentage values.

Description

An element in a document may obtain style information from an inline style attribute and from any number of style sheets in the style-sheet "cascade." Before the element can actually be displayed in a view, its style must be "computed" by extracting style information from the appropriate parts of the cascade.

This method allows access to those computed styles. By contrast, the style property of an element gives you access only to the inline styles of an element and tells you nothing about style-sheet attributes that apply to the element. Note that this method also provides a way to determine the actual pixel coordinates at which an element is rendered in this view.

getComputedStyle( ) is actually defined by the ViewCSS interface. In any DOM implementation that supports the View and CSS modules, any object that implements AbstractView always implements ViewCSS also. So, for simplicity, this method has been listed with AbstractView.

In Internet Explorer, similar functionality is available through the nonstandard currentStyle property of each HTMLElement object.

See Also

CSS2Properties, CSSStyleDeclaration, Reference

Attran attribute of a document element

Availability

DOM Level 1 Core

Inherits from/Overrides

Node Figure Attr

Properties

readonly String name
The name of the attribute.

readonly Element ownerElement [DOM Level 2]
The Element object that contains this attribute, or null if the Attr object is not currently associated with any Element.

readonly boolean specified
true if the attribute was explicitly specified in the document source or set by a script. false if the attribute was not explicitly specified but a default value is specified in the document's DTD.

String value
The value of the attribute. When reading this property, the attribute value is returned as a string. When you set this property to a string, it automatically creates a Text node that contains the same text and makes that Text node the sole child of the Attr object.

Description

An Attr object represents an attribute of an Element node. Attr objects are associated with Element nodes but are not directly part of the document tree (and have a null parentNode property). You can obtain an Attr object through the attributes property of the Node interface or by calling the getAttributeNode( ) method of the Element interface.

Attr objects are nodes, and the value of an Attr is represented by the child nodes of the Attr node. In HTML documents, this is simply a single Text node. In XML documents, however, Attr nodes may have both Text and EntityReference children. The value property provides a shortcut for reading and writing the value of an attribute as a String.

In most cases, the easiest way to work with element attributes is with the getAttribute( ) and setAttribute( ) methods of the Element interface. These methods use strings for attribute names and values and avoid the use of Attr nodes altogether.

See Also

Element

Passed to

Element.removeAttributeNode( ), Element.setAttributeNode( ), Element.setAttributeNodeNS( )

Returned by

Document.createAttribute( ), Document.createAttributeNS( ), Element.getAttributeNode( ), Element.getAttributeNodeNS( ), Element.removeAttributeNode( ), Element.setAttributeNode( ), Element.setAttributeNodeNS( )

CDATASectiona CDATA section in an XML document

Availability

DOM Level 1 XML

Inherits from/Overrides

Node Figure CharacterData Figure Text Figure CDATASection

Description

This infrequently used interface represents a CDATA section in an XML document. Programmers working with HTML documents never encounter nodes of this type and do not need to use this interface.

CDATASection is a subinterface of Text and does not define any properties or methods of its own. The textual content of the CDATA section is available through the nodeValue property inherited from Node or through the data property inherited from CharacterData. Although CDATASection nodes can often be treated in the same way as Text nodes, note that the Node.normalize( ) method does not merge adjacent CDATA sections.

See Also

CharacterData, Text

Returned by

Document.createCDATASection( )

CharacterDatacommon functionality for Text and Comment nodes

Availability

DOM Level 1 Core

Inherits from/Overrides

Node Figure CharacterData

Subinterfaces

Comment, Text

Properties

String data
The text contained by this node.

readonly unsigned long length
The number of characters contained by this node.

Methods

appendData( )
Appends the specified string to the text contained by this node.

deleteData( )
Deletes text from this node, starting with the character at the specified offset and continuing for the specified number of characters.

insertData( )
Inserts the specified string into the text of this node at the specified character offset.

replaceData( )
Replaces the characters starting at the specified character offset and continuing for the specified number of characters with the specified string.

substringData( )
Returns a copy of the text starting at the specified character offset and continuing for the specified number of characters.

Description

CharacterData is the superinterface for Text and Comment nodes. Documents never contain CharacterData nodes; they contain only Text and Comment nodes. Since both of these node types have similar functionality, however, that functionality has been defined here so that both Text and Comment can inherit it.

See Also

Comment, Text

CharacterData.appendData( )append a string to a Text or Comment node

Availability

DOM Level 1 Core

Synopsis

void appendData(String arg) 
    throws DOMException;

Arguments

arg
The string to be appended to the Text or Comment node.

Throws

This method throws a DOMException with a code of NO_MODIFICATION_ALLOWED_ERR if called on a node that is read-only.

Description

This method appends the string arg to the end of the data property for this node.

CharacterData.deleteData( )delete characters from a Text or Comment node

Availability

DOM Level 1 Core

Synopsis

void deleteData(unsigned long offset, 
                unsigned long count) 
    throws DOMException;

Arguments

offset
The position of the first character to be deleted.

count
The number of characters to be deleted.

Throws

This method may throw a DOMException with one of the following code values:

INDEX_SIZE_ERR
The offset or count argument is negative, or offset is greater than the length of the Text or Comment node.

NO_MODIFICATION_ALLOWED_ERR
The node is read-only and may not be modified.

Description

This method deletes characters from this Text or Comment node, starting with the character at the position offset and continuing for count characters. If offset plus count is greater than the number of characters in the Text or Comment node, all characters from offset to the end of the string are deleted.

CharacterData.insertData( )insert a string into a Text or Comment node

Availability

DOM Level 1 Core

Synopsis

void insertData(unsigned long offset,
                String arg) 
    throws DOMException;

Arguments

offset
The character position within the Text or Comment node at which the string is to be inserted.

arg
The string to insert.

Throws

This method may throw a DOMException with one of the following code values in the following circumstances:

INDEX_SIZE_ERR
offset is negative or greater than the length of the Text or Comment node.

NO_MODIFICATION_ALLOWED_ERR
The node is read-only and may not be modified.

Description

This method inserts the specified string arg into the text of a Text or Comment node at the specified position offset.

CharacterData.replaceData( )replace characters of a Text or Comment node with a string

Availability

DOM Level 1 Core

Synopsis

void replaceData(unsigned long offset,
                 unsigned long count, String arg) 
    throws DOMException;

Arguments

offset
The character position within the Text or Comment node at which the replacement is to begin.

count
The number of characters to be replaced.

arg
The string that replaces the characters specified by offset and count.

Throws

This method may throw a DOMException with one of the following code values in the following circumstances:

INDEX_SIZE_ERR
offset is negative or greater than the length of the Text or Comment node, or count is negative.

NO_MODIFICATION_ALLOWED_ERR
The node is read-only and may not be modified.

Description

This method replaces count characters starting at position offset with the contents of the string arg. If the sum of offset and count is greater than the length of the Text or Comment node, all characters from offset on are replaced.

CharacterData.substringData( )extract a substring from a Text or Comment node

Availability

DOM Level 1 Core

Synopsis

String substringData(unsigned long offset, 
                     unsigned long count) 
    throws DOMException;

Arguments

offset
The position of the first character to be returned.

count
The number of characters in the substring to be returned.

Returns

A string that consists of count characters of the Text or Comment node starting with the character at position offset.

Throws

This method may throw a DOMException with one of the following code values:

INDEX_SIZE_ERR
offset is negative or greater than the length of the Text or Comment node, or count is negative.

DOMSTRING_SIZE_ERR
The specified range of text is too long to fit into a string in the browser's JavaScript implementation.

Description

This method extracts the substring that starts at position offset and continues for count characters from the text of a Text or Comment node. This method is useful only when the amount of text contained by the node is larger than the maximum number of characters that can fit in a string in a browser's JavaScript implementation. In this case, a JavaScript program cannot use the data property of the Text or Comment node directly and must instead work with shorter substrings of the node's text. This situation is unlikely to arise in practice.

Commentan HTML or XML comment

Availability

DOM Level 1 Core

Inherits from/Overrides

Node Figure CharacterData Figure Comment

Description

A Comment node represents a comment in an HTML or XML document. The content of the comment (i.e., the text between <!-- and -->) is available through the data property inherited from the CharacterData interface or through the nodeValue property inherited from the Node interface. This content may be manipulated using the various methods inherited from CharacterData.

See Also

CharacterData

Returned by

Document.createComment( )

Countera CSS counter( ) or counters( ) specification

Availability

DOM Level 2 CSS

Properties

readonly String identifier
The name of the counter.

readonly String listStyle
The list style for the counter.

readonly String separator
The separator string for nested counters.

Description

This interface represents a CSS counter( ) or counters( ) value. Consult a CSS reference for more information.

See Also

Returned by

CSSPrimitiveValue.getCounterValue( )

CSS2Propertiesconvenience properties for all CSS2 attributes

Availability

DOM Level 2 CSS2

Properties

This interface defines a large number of properties: one property for each CSS attribute defined by the CSS2 specification. The property names correspond closely to the CSS attribute names, with minor changes required to avoid syntax errors in JavaScript. Multiword attributes that contain hyphens, such as "font-family," are written without hyphens in JavaScript, and each word after the first is capitalized: fontFamily. Also, the "float" attribute conflicts with the reserved word float, so it translates to the property cssFloat.

The complete set of properties is listed in the following table. Since the properties correspond directly to CSS attributes, no individual documentation is given for each property. See a CSS reference, such as Cascading Style Sheets: The Definitive Guide, by Eric A. Meyer (O'Reilly), for the meaning and legal values of each. All of the properties are strings. Setting any of these properties may throw the same exceptions, for the same reasons as a call to CSSStyleDeclaration.setProperty( ).

azimuth

background

backgroundAttachment

backgroundColor

backgroundImage

backgroundPosition

backgroundRepeat

border

borderBottom

borderBottomColor

borderBottomStyle

borderBottomWidth

borderCollapse

borderColor

borderLeft

borderLeftColor

borderLeftStyle

borderLeftWidth

borderRight

borderRightColor

borderRightStyle

borderRightWidth

borderSpacing

borderStyle

borderTop

borderTopColor

borderTopStyle

borderTopWidth

borderWidth

bottom

captionSide

clear

clip

color

content

counterIncrement

counterReset

cssFloat

cue

cueAfter

cueBefore

cursor

direction

display

elevation

emptyCells

font

fontFamily

fontSize

fontSizeAdjust

fontStretch

fontStyle

fontVariant

fontWeight

height

left

letterSpacing

lineHeight

listStyle

listStyleImage

listStylePosition

listStyleType

margin

marginBottom

marginLeft

marginRight

marginTop

markerOffset

marks

maxHeight

maxWidth

minHeight

minWidth

orphans

outline

outlineColor

outlineStyle

outlineWidth

overflow

padding

paddingBottom

paddingLeft

paddingRight

paddingTop

page

pageBreakAfter

pageBreakBefore

pageBreakInside

pause

pauseAfter

pauseBefore

pitch

pitchRange

playDuring

position

quotes

richness

right

size

speak

speakHeader

speakNumeral

speakPunctuation

speechRate

stress

tableLayout

textAlign

textDecoration

textIndent

textShadow

textTransform

top

unicodeBidi

verticalAlign

visibility

voiceFamily

volume

whiteSpace

widows

width

wordSpacing

zIndex

   

Description

This interface defines one property for each CSS attribute defined by the CSS2 specification. If the DOM implementation supports this interface (which is part of the "CSS2" feature), all CSSStyleDeclaration objects also implement CSS2Properties. Reading one of the properties defined by this interface is equivalent to calling getPropertyValue( ) for the corresponding CSS attribute, and setting the value of one of these properties is equivalent to calling setProperty( ) for the corresponding attribute. The properties defined by CSS2Properties include properties that correspond to CSS shortcut attributes, and CSS2Properties handles these shortcut properties correctly.

See Also

CSSStyleDeclaration

CSSCharsetRulean @charset rule in a CSS style sheet

Availability

DOM Level 2 CSS

Inherits from/Overrides

CSSRule Figure CSSCharsetRule

Properties

String encoding
The character encoding specified by the @charset rule. If you set this property to an illegal value, a DOMException with a code of SYNTAX_ERR is thrown. If the rule or style sheet is read-only, an attempt to set this property throws a DOMException with a code of NO_MODIFICATION_ALLOWED_ERR.

Description

This interface represents an @charset rule in a CSS style sheet. Consult a CSS reference for details.

CSSFontFaceRulean @font-face rule in a CSS style sheet

Availability

DOM Level 2 CSS

Inherits from/Overrides

CSSRule Figure CSSFontFaceRule

Properties

readonly CSSStyleDeclaration style
The set of styles for this rule.

Description

This interface represents an @font-face rule in a CSS style sheet. Consult a CSS reference for details.

CSSImportRulean @import rule in a CSS style sheet

Availability

DOM Level 2 CSS

Inherits from/Overrides

CSSRule Figure CSSImportRule

Properties

readonly String href
The URL of the imported style sheet. The value of this property does not include the "url( )" delimiter around the URL value.

readonly MediaList media
A list of media types to which the imported style sheet applies.

readonly CSSStyleSheet styleSheet
The CSSStyleSheet object that represents the imported style sheet, or null if the style sheet has not yet been loaded or if the style sheet was not loaded because, for example, the media type did not apply.

Description

This interface represents an @import rule in a CSS style sheet. The styleSheet property represents the imported style sheet.

CSSMediaRulean @media rule in a CSS style sheet

Availability

DOM Level 2 CSS

Inherits from/Overrides

CSSRule Figure CSSMediaRule

Properties

readonly CSSRuleList cssRules
An array (technically, a CSSRuleList) of all the rules nested within this @media rule block.

readonly MediaList media
The list of media types to which the nested rules apply.

Methods

deleteRule( )
Deletes the nested rule at the specified position.

insertRule( )
Inserts a new rule at the specified position within this @media rule block.

Description

This interface represents an @media rule, and all of its nested rules, in a CSS style sheet. It defines methods that allow you to insert and delete nested rules. Consult a CSS reference for details.

CSSMediaRule.deleteRule( )delete a rule in an @media block

Availability

DOM Level 2 CSS

Synopsis

void deleteRule(unsigned long index)
    throws DOMException;

Arguments

index
The position within the @media rule block of the rule to be deleted.

Throws

This method throws a DOMException with one of the following code values in the following circumstances:

INDEX_SIZE_ERR
index is negative or is greater than or equal to the number of rules in cssRules.

NO_MODIFICATION_ALLOWED_ERR
The rule is read-only.

Description

This method deletes the rule at the specified position in the cssRules array.

CSSMediaRule.insertRule( )insert a new rule into an @media block

Availability

DOM Level 2 CSS

Synopsis

unsigned long insertRule(String rule, 
                         unsigned long index) 
    throws DOMException;

Arguments

rule
The complete, parseable CSS string representation of the rule to be added.

index
The position at which the new rule is to be inserted into the cssRules array, or the cssRules.length to append the new rule at the end of the array.

Returns

The value of the index argument.

Throws

This method throws a DOMException with one of the following code values in the following circumstances:

HIERARCHY_REQUEST_ERR
CSS syntax does not allow the specified rule at the specified position.

INDEX_SIZE_ERR
index is negative or greater than cssRules.length.

NO_MODIFICATION_ALLOWED_ERR
This @media rule and its cssRules array are read-only.

SYNTAX_ERR
The specified rule contains a syntax error.

Description

This method inserts the specified rule into the cssRules array at the specified index.

CSSPageRulean @page rule in a CSS style sheet

Availability

DOM Level 2 CSS

Inherits from/Overrides

CSSRule Figure CSSPageRule

Properties

String selectorText
The page selector text for this rule. Setting this property to an illegal value throws a DOMException with a code of SYNTAX_ERR. Setting this property when the rule is read-only throws a DOMException with a code of NO_MODIFICATION_ALLOWED_ERR.

readonly CSSStyleDeclaration style
The set of styles for this rule.

Description

This interface represents an @page rule in a CSS style sheet, which is typically used to specify the page layout for printing. Consult a CSS reference for details.

CSSPrimitiveValuea single CSS style value

Availability

DOM Level 2 CSS

Inherits from/Overrides

CSSValue Figure CSSPrimitiveValue

Constants

The following constants are the legal values for the primitiveType property. They specify the type of the value and, for numeric values, the units in which the value is represented.

unsigned short CSS_UNKNOWN = 0
The value is not recognized, and the implementation does not know how to parse it. The textual representation of the value is available through the cssText property.

unsigned short CSS_NUMBER = 1
A unitless number. Query with getFloatValue( ).

unsigned short CSS_PERCENTAGE = 2
A percentage. Query with getFloatValue( ).

unsigned short CSS_EMS = 3
A relative length measured in ems (the height of the current font). Query with getFloatValue( ).

unsigned short CSS_EXS = 4
A relative length measured in exs (the "x-height" of the current font). Query with getFloatValue( ).

unsigned short CSS_PX = 5
A length measured in pixels. Query with getFloatValue( ). Pixel lengths are relative measurements, in the sense that their size depends on the display resolution, and they cannot be converted to inches, millimeters, points, or other absolute lengths. However, pixels are also one of the most commonly used units, and they are treated as absolute values for the purposes of AbstractView.getComputedStyle( ), for example.

unsigned short CSS_CM = 6
An absolute length measured in centimeters. Query with getFloatValue( ).

unsigned short CSS_MM = 7
An absolute length measured in millimeters. Query with getFloatValue( ).

unsigned short CSS_IN = 8
An absolute length measured in inches. Query with getFloatValue( ).

unsigned short CSS_PT = 9
An absolute length measured in points (1/72 of an inch). Query with getFloatValue( ).

unsigned short CSS_PC = 10
An absolute length measured in picas (12 points). Query with getFloatValue( ).

unsigned short CSS_DEG = 11
An angle measured in degrees. Query with getFloatValue( ).

unsigned short CSS_RAD = 12
An angle measured in radians. Query with getFloatValue( ).

unsigned short CSS_GRAD = 13
An angle measured in grads. Query with getFloatValue( ).

unsigned short CSS_MS = 14
A time measured in milliseconds. Query with getFloatValue( ).

unsigned short CSS_S = 15
A time measured in seconds. Query with getFloatValue( ).

unsigned short CSS_HZ = 16
A frequency measured in hertz. Query with getFloatValue( ).

unsigned short CSS_KHZ = 17
A frequency measured in kilohertz. Query with getFloatValue( ).

unsigned short CSS_DIMENSION = 18
A unitless dimension. Query with getFloatValue( ).

unsigned short CSS_STRING = 19
A string. Query with getStringValue( ).

unsigned short CSS_URI = 20
A URI. Query with getStringValue( ).

unsigned short CSS_IDENT = 21
An identifier. Query with getStringValue( ).

unsigned short CSS_ATTR = 22
An attribute function. Query with getStringValue( ).

unsigned short CSS_COUNTER = 23
A counter. Query with getCounterValue( ).

unsigned short CSS_RECT = 24
A rectangle. Query with getRectValue( ).

unsigned short CSS_RGBCOLOR = 25
A color. Query with getRGBColorValue( ).

Properties

readonly unsigned short primitiveType
The type of this value. This property holds one of the constants defined in the previous section.

Methods

getCounterValue( )
For values of type CSS_COUNTER, returns the Counter object that represents the value.

getFloatValue( )
Returns a numeric value, converting it, if necessary, to the specified units.

getRectValue( )
For values of type CSS_RECT, returns the Rect object that represents the value.

getRGBColorValue( )
For values of type CSS_RGBCOLOR, returns the RGBColor object that represents the value.

getStringValue( )
Returns the value as a string.

setFloatValue( )
Sets a numeric value to the specified number of the specified units.

setStringValue( )
Sets a string value to the specified string of the specified type.

Description

This subinterface of CSSValue represents a single CSS value. Contrast it with the CSSValueList interface, which represents a list of CSS values. The word "primitive" in the name of this interface is misleading; this interface can represent some complex types of CSS values, such as counters, rectangles, and colors.

The primitiveType property holds one of the previously defined constants and specifies the type of the value. The various methods defined by this interface allow you to query values of various types and also to set numeric and string values.

See Also

Counter, CSSValue, CSSValueList, Rect, RGBColor

Type of

RGBColor.blue, RGBColor.green, RGBColor.red, Rect.bottom, Rect.left, Rect.right, Rect.top

CSSPrimitiveValue.getCounterValue( )return a Counter value

Availability

DOM Level 2 CSS

Synopsis

Counter getCounterValue( )    
    throws DOMException;

Returns

The Counter object that represents the value of this CSSPrimitiveValue.

Throws

This method throws a DOMException with a code of INVALID_ACCESS_ERR if the primitiveType property is not CSS_COUNTER.

Description

This method returns a Counter object that represents a CSS counter. There is no corresponding setCounterValue( ), but you can modify the value by setting the properties of the returned Counter object.

CSSPrimitiveValue.getFloatValue( )get a numeric value, possibly converting units

Availability

DOM Level 2 CSS

Synopsis

float getFloatValue(unsigned short unitType) 
    throws DOMException;

Arguments

unitType
One of the CSSPrimitiveValue type constants that specifies the desired units for the returned value.

Returns

The floating-point numeric value of this CSSPrimitiveValue, expressed in the specified units.

Throws

This method throws a DOMException with a code of INVALID_ACCESS_ERR if this CSSPrimitiveValue holds a non-numeric value, or if the value cannot be converted to the requested type of units. (See the next section for more about unit conversion.)

Description

For CSSPrimitiveValue objects that hold numeric values, this method converts those values to the specified units and returns the converted values.

Only certain types of unit conversions are allowed. Lengths may be converted to lengths, angles to angles, times to times, and frequencies to frequencies. Obviously, however, a length measured in millimeters cannot be converted to a frequency measured in kilohertz. Also, not all lengths can be converted. Relative lengths (lengths measured in ems, exs, or pixels) can be converted to other relative lengths but cannot be converted to absolute lengths. Similarly, absolute lengths cannot be converted to relative lengths. Finally, percentage values cannot be converted to any other unit type, except for color percentage values, which express a percentage of 255 and can be converted to the CSS_NUMBER type.

CSSPrimitiveValue.getRectValue( )return a Rect value

Availability

DOM Level 2 CSS

Synopsis

Rect getRectValue( )    
     throws DOMException;

Returns

The Rect object that represents the value of this CSSPrimitiveValue.

Throws

This method throws a DOMException with a code of INVALID_ACCESS_ERR if the primitiveType property is not CSS_RECT.

Description

This method returns a Rect object that represents a CSS rectangle. There is no corresponding setRectValue( ) method, but you can modify the value by setting the properties of the returned Rect object.

CSSPrimitiveValue.getRGBColorValue( )get the RGBColor value

Availability

DOM Level 2 CSS

Synopsis

RGBColor getRGBColorValue( )    
    throws DOMException;

Returns

The RGBColor object that represents the value of this CSSPrimitiveValue.

Throws

This method throws a DOMException with a code of INVALID_ACCESS_ERR if the primitiveType property is not CSS_RGBCOLOR.

Description

This method returns an RGBColor object that represents a color. There is no corresponding setRGBColorValue( ) method, but you can modify the value by setting the properties of the returned RGBColor object.

CSSPrimitiveValue.getStringValue( )query a CSS string value

Availability

DOM Level 2 CSS

Synopsis

String getStringValue( )    
    throws DOMException;

Returns

The string value of this CSSPrimitiveValue.

Throws

This method throws a DOMException with a code of INVALID_ACCESS_ERR if the primitiveType property is not CSS_STRING, CSS_URI, CSS_IDENT, or CSS_ATTR.

CSSPrimitiveValue.setFloatValue( )set the numeric value

Availability

DOM Level 2 CSS

Synopsis

void setFloatValue(unsigned short unitType, 
                   float floatValue)
    throws DOMException;

Arguments

unitType
One of the CSSPrimitiveValue constants that specifies the numeric type units for this value.

floatValue
The new value (measured in unitType units).

Throws

This method throws a DOMException with a code of NO_MODIFICATION_ALLOWED_ERR if the CSS attribute with which this value is associated is read-only. It throws a DOMException with a code of INVALID_ACCESS_ERR if that CSS attribute does not allow numeric values or does not allow values with the specified unitType.

Description

This method specifies the unit type and numeric value for this CSSPrimitiveValue.

CSSPrimitiveValue.setStringValue( )set the string value

Availability

DOM Level 2 CSS

Synopsis

void setStringValue(unsigned short stringType, 
                    String stringValue) 
    throws DOMException;

Arguments

stringType
The type of the string being set. This must be one of the CSSPrimitiveValue constants CSS_STRING, CSS_URI, CSS_IDENT, or CSS_ATTR.

stringValue
The new string value to be set.

Throws

This method throws a DOMException with a code of NO_MODIFICATION_ALLOWED_ERR if the CSS attribute with which this value is associated is read-only. It throws a DOMException with a code of INVALID_ACCESS_ERR if that CSS attribute does not allow string values or does not allow values with the specified stringType.

Description

This method sets the string value and string type for this CSSPrimitiveValue.

CSSRulea rule in a CSS style sheet

Availability

DOM Level 2 CSS

Subinterfaces

CSSCharsetRule, CSSFontFaceRule, CSSImportRule, CSSMediaRule, CSSPageRule, CSSStyleRule, CSSUnknownRule

Constants

These constants represent the various types of rules that may appear in a CSS style sheet. They are the legal values of the type property, and they specify which of the above subinterfaces this object implements.

unsigned short UNKNOWN_RULE = 0;    // CSSUnknownRule
unsigned short STYLE_RULE = 1;      // CSSStyleRule
unsigned short CHARSET_RULE = 2;    // CSSCharsetRule
unsigned short IMPORT_RULE = 3;     // CSSImportRule
unsigned short MEDIA_RULE = 4;      // CSSMediaRule
unsigned short FONT_FACE_RULE = 5;  // CSSFontFaceRule
unsigned short PAGE_RULE = 6;       // CSSPageRule

Properties

String cssText
The textual representation of the rule. If you set this property, it may throw a DOMException with one of the following code values for one of the following reasons:

HIERARCHY_REQUEST_ERR
The specified rule is not legal at this location in the style sheet.

INVALID_MODIFICATION_ERR
The new value of the property is a rule of a different type than the original value.

NO_MODIFICATION_ALLOWED_ERR
The rule or the style sheet that contains it is read-only.

SYNTAX_ERR
The specified string is not legal CSS syntax.

readonly CSSRule parentRule
The containing rule of this rule, or null if this rule does not have a parent. An example of a CSS rule with a parent is a style rule within an @media rule.

readonly CSSStyleSheet parentStyleSheet
The CSSStyleSheet object that contains this rule.

readonly unsigned short type
The type of CSS rule this object represents. The legal values for this property are the previously listed constants. This CSSRule interface is never implemented directly, and the value of this property specifies which more specific subinterface is implemented by this object.

Description

This interface defines properties that are common to all types of rules in CSS style sheets. No object directly implements this interface; instead, they implement one of the more specific subinterfaces listed earlier. The most important subinterface is probably CSSStyleRule, which describes a CSS rule that defines a document style.

See Also

CSSStyleRule

Type of

CSSRule.parentRule, CSSStyleDeclaration.parentRule, CSSStyleSheet.ownerRule

Returned by

CSSRuleList.item( )

CSSRuleListan array of CSSRule objects

Availability

DOM Level 2 CSS

Properties

readonly unsigned long length
The number of CSSRule objects in this CSSRuleList array.

Methods

item( )
Returns the CSSRule object at the specified position. Instead of explicitly calling this method, JavaScript allows you to simply treat the CSSRuleList object as an array and to index it using standard square-bracket array notation. If the specified index is too large, this method returns null.

Description

This interface defines a read-only ordered list (i.e., an array) of CSSRule objects. The length property specifies the number of rules in the list, and the item( ) method allows you to retrieve the rule at a specified position. In JavaScript, CSSRuleList objects behave like JavaScript arrays, and you can query an element from the list using square-bracket array notation instead of calling the item( ) method. (Note, however, that you cannot assign new nodes into a CSSRuleList using square brackets.)

See Also

Type of

CSSMediaRule.cssRules, CSSStyleSheet.cssRules

CSSRuleList.item( )get the CSSRule at the specified position

Availability

DOM Level 2 CSS

Synopsis

CSSRule item(unsigned long index);

Arguments

index
The position of the rule to retrieve.

Returns

The CSSRule object at the specified position, or null if index is not a valid position.

CSSStyleDeclarationa set of CSS style attributes and their values

Availability

DOM Level 2 CSS

Also Implements

If the implementation supports the "CSS2" feature in addition to the "CSS" feature (as most web browsers do), all objects that implement this interface also implement the CSS2Properties interface. CSS2Properties provides commonly used shortcut properties for setting and querying the values of CSS attributes. See CSS2Properties for details.

Properties

String cssText
The textual representation of the style attributes and their values. This property consists of the complete text of the style rule, minus the element selector and the curly braces that surround the attributes and values. Setting this property to an illegal value throws a DOMException with a code of SYNTAX_ERR. Setting it for a read-only style sheet or rule throws a DOMException with a code of NO_MODIFICATION_ALLOWED_ERR.

readonly unsigned long length
The number of style attributes in this style declaration.

readonly CSSRule parentRule
The CSSRule object that contains this CSSStyleDeclaration, or null if this style declaration is not part of a CSS rule (such as for CSSStyleDeclaration objects that represent inline HTML style attributes).

Methods

getPropertyCSSValue( )
Returns a CSSValue object that represents the value of the named CSS attribute, or null if that attribute is not explicitly set in this style declaration block or if the named style is a "shortcut" attribute.

getPropertyPriority( )
Returns the string "important" if the named CSS attribute is explicitly set in this declaration block and has the !important priority qualifier specified. If the attribute is not specified, or has no priority, returns the empty string.

getPropertyValue( )
Returns the value of the named CSS attribute as a string. Returns the empty string if the attribute is not specified in this declaration block.

item( )
Returns the name of the CSS attribute at the specified position in this style declaration block. In JavaScript, the CSSStyleDeclaration object can be treated as an array and indexed using square brackets instead. See also the length property.

removeProperty( )
Deletes a named CSS attribute from this declaration block.

setProperty( )
Sets a named CSS attribute to the specified string value and priority for this declaration block.

Description

This attribute represents a CSS style declaration block: a set of CSS attributes and their values, separated from each other by semicolons. The style declaration block is the portion of a style rule within curly braces in a CSS style sheet. The value of the HTML style attribute also constitutes a style declaration block.

The item( ) method and the length property allow you to loop through the names of all CSS attributes specified in this declaration block. In JavaScript, you can also simply treat the CSSStyleDeclaration object as an array and index it using square-bracket notation instead of calling the item( ) method explicitly. Once you have the names of the CSS attributes specified in this declaration, you can use other methods of this interface to query the values of those attributes. getPropertyValue( ) returns the value as a string, and getPropertyCSSValue( ) returns the attribute value as a CSSValue object. (Note that the DOM API refers to CSS style attributes as "properties." I use the term "attributes" here to avoid confusing them with JavaScript object properties.)

In most web browsers, every object that implements CSSStyleDeclaration also implements the CSS2Properties interface, which defines an object property for each CSS attribute defined by the CSS2 specification. You can read and write the values of these convenience properties instead of calling getPropertyValue( ) and setProperty( ).

See Also

CSS2Properties

Type of

CSSFontFaceRule.style, CSSPageRule.style, CSSStyleRule.style, HTMLElement.style

Returned by

Document.getOverrideStyle( ), AbstractView.getComputedStyle( )

CSSStyleDeclaration.getPropertyCSSValue( )return a CSS attribute value as an object

Availability

DOM Level 2 CSS

Synopsis

CSSValue getPropertyCSSValue(String propertyName);

Arguments

propertyName
The name of the desired CSS attribute.

Returns

A CSSValue object that represents the value of the named attribute if it is explicitly specified in this style declaration, or null if the named attribute is not specified. This method also returns null if propertyName specifies a CSS shorthand attribute, since shorthand attributes specify more than one value and cannot be represented with CSSValue objects.

CSSStyleDeclaration.getPropertyPriority( )get the priority of a CSS attribute

Availability

DOM Level 2 CSS

Synopsis

String getPropertyPriority(String propertyName);

Arguments

propertyName
The name of the CSS attribute.

Returns

The string "important" if the named CSS attribute is explicitly specified in this declaration block and has the !important priority modifier. Returns the empty string otherwise.

CSSStyleDeclaration.getPropertyValue( )get the value of a CSS attribute as a string

Availability

DOM Level 2 CSS

Synopsis

String getPropertyValue(String propertyName);

Arguments

propertyName
The name of the CSS attribute whose value is desired.

Returns

The string value of the named CSS attribute, or the empty string if that attribute is not explicitly set in this declaration block.

Description

This method returns the value of the named CSS attribute as a string. Unlike getPropertyCSSValue( ), this method works with shortcut attributes as well as regular attributes. See also the various convenience properties of the CSS2Properties interface.

CSSStyleDeclaration.item( )get the CSS attribute name at the specified position

Availability

DOM Level 2 CSS

Synopsis

String item(unsigned long index);

Arguments

index
The position of the desired CSS attribute name.

Returns

The name of the CSS attribute at index, or the empty string if index is negative or greater than or equal to the length property.

Description

The CSSStyleDeclaration interface represents a collection of CSS style attributes and their values. This method allows you to query the name of the CSS attribute by position and, in conjunction with the length property, allows you to iterate through the set of CSS attributes specified in this style declaration. Note that the order of CSS attributes as returned by this method does not necessarily correspond to the order in which they appear in the document or style sheet source.

As an alternative to this item( ) method, JavaScript allows you to simply treat a CSSStyleDeclaration object as an array of CSS attribute names and use standard square-bracket array syntax to obtain the attribute name at a specified position.

CSSStyleDeclaration.removeProperty( )delete a CSS attribute specification

Availability

DOM Level 2 CSS

Synopsis

String removeProperty(String propertyName) 
    throws DOMException;

Arguments

propertyName
The name of the CSS attribute to be deleted.

Returns

The value of the named CSS attribute as a string, or the empty string if the named attribute is not explicitly specified in this style declaration.

Throws

If this style declaration is read-only, this method throws a DOMException with a code of NO_MODIFICATION_ALLOWED_ERR.

Description

This method deletes a named attribute from this style declaration block and returns the value of the attribute.

CSSStyleDeclaration.setProperty( )set a CSS style attribute

Availability

DOM Level 2 CSS

Synopsis

void setProperty(String propertyName,
                 String value, 
                 String  priority) 
    throws DOMException;

Arguments

propertyName
The name of the CSS attribute to set.

value
The new value of the attribute, as a string.

priority
The new priority of the attribute. This argument should be "important" if the attribute specification is !important; otherwise, it should be the empty string.

Throws

This method throws a DOMException with a code of SYNTAX_ERR if the specified value argument is malformed. It throws a DOMException with a code of NO_MODIFICATION_ALLOWED_ERR if the style declaration or the attribute being set is read-only.

Description

This method adds the named CSS attribute with its value and priority to this style declaration, or, if the declaration already contains a value for the named attribute, it simply sets the value and priority for that existing attribute.

Using setProperty( ) to add a new CSS attribute to a style declaration may insert the new attribute at any position and may, in fact, totally shuffle the order of all existing attributes. Therefore, you should not use setProperty( ) while you are iterating through the set of attribute names with the item( ) method.

CSSStyleRulea style rule in a CSS style sheet

Availability

DOM Level 2 CSS

Inherits from/Overrides

CSSRule Figure CSSStyleRule

Properties

String selectorText
The selector text that specifies the document elements this style rule applies to. Setting this property raises a DOMException with a code of NO_MODIFICATION_ALLOWED_ERR if the rule is read-only, or a code of SYNTAX_ERR if the new value does not follow CSS syntax rules.

readonly CSSStyleDeclaration style
The style values that should be applied to elements specified by selectorText.

Description

This interface represents a style rule in a CSS style sheet. Style rules are the most common and important kinds of rules in style sheets: they specify style information that is to be applied to a specific set of document elements. selectorText is the string representation of the element selector for this rule, and style is a CSSStyleDeclaration object that represents the set of style names and values to apply to the selected elements.

See Also

CSSStyleDeclaration

CSSStyleSheeta CSS style sheet

Availability

DOM Level 2

Inherits from/Overrides

CSS StyleSheet Figure CSSStyleSheet

Properties

readonly CSSRuleList cssRules
An array (technically, a CSSRuleList) of the CSSRule objects that comprise the style sheet. This includes all at-rules in addition to the actual style rules.

readonly CSSRule ownerRule
If this style sheet was imported by an @import rule in another style sheet, this property holds the CSSImportRule object that represents that @import rule. Otherwise, it is null. When this property is non-null, the inherited ownerNode property is null.

Methods

deleteRule( )
Deletes the rule at the specified position.

insertRule( )
Inserts a new rule at the specified position.

Description

This interface represents a CSS style sheet. The cssRules property lists the rules contained in the style sheet, and the insertRule( ) and deleteRule( ) methods allow you to add and delete rules from that list.

See Also

StyleSheet

Type of

CSSImportRule.styleSheet, CSSRule.parentStyleSheet

Returned by

DOMImplementation.createCSSStyleSheet( )

CSSStyleSheet.deleteRule( )delete a rule from a style sheet

Availability

DOM Level 2 CSS

Synopsis

void deleteRule(unsigned long index)
    throws DOMException;

Arguments

index
The index within the cssRules array of the rule to be deleted.

Throws

This method throws a DOMException with a code of INDEX_SIZE_ERR if index is negative or greater than or equal to cssRules.length. It throws a DOMException with a code of NO_MODIFICATION_ALLOWED_ERR if this style sheet is read-only.

Description

This method deletes the rule at the specified index from the cssRules array.

CSSStyleSheet.insertRule( )insert a rule into a style sheet

Availability

DOM Level 2 CSS

Synopsis

unsigned long insertRule(String rule,
                         unsigned long index) 
    throws DOMException;

Arguments

rule
The complete, parseable text representation of the rule to be added to the style sheet. For style rules, this includes both the element selector and the style information.

index
The position in the cssRules array at which the rule is to be inserted or appended.

Returns

The value of the index argument.

Throws

This method throws a DOMException with one of the following code values in the following circumstances:

HIERARCHY_REQUEST_ERR
CSS syntax does not allow the specified rule at the specified location.

INDEX_SIZE_ERR
index is negative or greater then cssRules.length.

NO_MODIFICATION_ALLOWED_ERR
The style sheet is read-only.

SYNTAX_ERR
The specified rule text contains a syntax error.

Description

This method inserts (or appends) a new CSS rule at the specified index of the cssRules array of this style sheet.

CSSUnknownRulean unrecognized rule in a CSS style sheet

Availability

DOM Level 2

Inherits from/Overrides

CSS CSSRule Figure CSSUnknownRule

Description

This interface represents a rule in a CSS style sheet that the browser did not recognize and could not parse (typically because it is defined by a version of the CSS standard that the browser does not support). Note that this interface does not define any properties or methods of its own. The text of the unrecognized rule is available through the inherited cssText property.

CSSValuethe value of a CSS style attribute

Availability

DOM Level 2 CSS

Subinterfaces

CSSPrimitiveValue, CSSValueList

Constants

The following constants specify the valid values for the cssValueType property:

unsigned short CSS_INHERIT = 0
This constant represents the special value "inherit", which means that the actual value of the CSS style attribute is inherited. The cssText property is "inherit" in this case.

unsigned short CSS_PRIMITIVE_VALUE = 1
The value is a primitive value. This CSSValue object also implements the more specific CSSPrimitiveValue subinterface.

unsigned short CSS_VALUE_LIST = 2
The value is a compound value consisting of a list of values. This CSSValue object also implements the more specific CSSValueList subinterface and behaves as an array of CSSValue objects.

unsigned short CSS_CUSTOM = 3
This constant is defined to allow extensions to the CSS object model. It specifies that this CSSValue represents a value of some type that is not defined by the CSS or DOM standards. If you are working with an implementation that supports such extensions, the CSSValue object may also implement some other interface (such as the SVGColor interface defined by the Scalable Vector Graphics standard) that you can use.

Properties

String cssText
The textual representation of the value. Setting this property may throw a DOMException. A code of SYNTAX_ERR indicates that the new value does not follow legal CSS syntax. A code of INVALID_MODIFICATION_ERR specifies that you tried to set a value of a different type than the original value. A code of NO_MODIFICATION_ALLOWED_ERR indicates that the value is read-only.

readonly unsigned short cssValueType
The kind of value this object represents. The four legal values of this property are defined by the previously listed constants.

Description

This interface represents the value of a CSS attribute. The cssText property gives the value in textual form. If the cssValueType property is CSSValue.CSS_PRIMITIVE_VALUE, this CSSValue object also implements the more specific CSSPrimitiveValue interface. If cssValueType is CSSValue.CSS_VALUE_LIST, this CSSValue represents a list of values and also implements the CSSValueList interface.

See Also

CSSPrimitiveValue, CSSValueList

Returned by

CSSStyleDeclaration.getPropertyCSSValue( ), CSSValueList.item( )

CSSValueLista CSSValue that holds an array of CSSValue objects

Availability

DOM Level 2 CSS

Inherits from/Overrides

CSSValue Figure CSSValueList

Properties

readonly unsigned long length
The number of CSSValue objects in this array.

Methods

item( )
Returns the CSSValue object at the specified position in the array, or null if the specified position is negative or if it is greater than or equal to length.

Description

This interface represents an array of CSSValue objects and is itself a type of CSSValue. The item( ) method can be used to retrieve the CSSValue object at a specified position, but in JavaScript, it is easier to simply index the array using standard square-bracket notation.

The order of CSSValue objects in a CSSValueList array is the order in which they appear in the CSS style declaration. Some CSS attributes whose value is a CSSValueList may also have the value none. This special value translates into a CSSValueList object with a length of 0.

CSSValueList.item( )get the CSSValue at the specified position

Availability

DOM Level 2 CSS

Synopsis

CSSValue item(unsigned long index);

Arguments

index
The position of the desired CSSValue.

Returns

The CSSValue object at the specified position in this CSSValueList, or null if index is negative or is greater than or equal to length.