JavaScript 1.5+, JScript 5+
Nav6+, IE5+
DOM CSS object.
Listing 13.1 illustrates reading the properties of the Counter
object.
<html>
<script language="JScript">
<!--
var counterObj = primitiveValObj.getCounterValue();
var idVal = counterObj.identifier;
var listStyleVal = counterObj.listStyle;
var separatorVal = counterObj.separator;
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
CounterObj.identifier
The read-only property identifier of the Counter
object is used for to identify the counter.
Listing 13.2 illustrates reading the identifier property of the Counter
object.
<html>
<script language="JScript">
<!--
var counterObj = primitiveValObj.getCounterValue();
var idVal = counterObj.identifier;
var listStyleVal = counterObj.listStyle;
var separatorVal = counterObj.separator;
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
counterObj.listStyle
The read-only property listStyle
of the Counter
object is of type String
. The listStyle
property is used for the style of the list.
Listing 13.3 illustrates reading the listStyle
property of the Counter
object.
<html>
<script language="JScript">
<!--
var counterObj = primitiveValObj.getCounterValue();
var idVal = counterObj.identifier;
var listStyleVal = counterObj.listStyle;
var separatorVal = counterObj.separator;
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
Counter.separator
The read-only property separator
of the Counter
object is of type String
. The separator
property is used for the separator of the nested counters.
Listing 13.4 illustrates reading the separator
property of the Counter
object.
<html>
<script language="JScript">
<!--
var counterObj = primitiveValObj.getCounterValue();
var idVal = counterObj.identifier;
var listStyleVal = counterObj.listStyle;
var separatorseparatorVal = rectObj.separator;
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
DOM CSS Object.
The CSSCharsetRule
object represents a @charset rule in a CSSStyleSheet
. CSSCharsetRule
extends CSSRule
. The property associated with the CSSCharsetRule
object is as follows:
Item | Description |
| This is a read-only property of type |
Listing 13.5 demonstrates reading the encoding
property of the CSSCharsetRule
object.
<html>
<script language="JScript">
<!--
document.writewrite(cssCharsetRuleObj);
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssCharsetRuleObj.encoding
The read-only property encoding
of the CSSCharsetRule
object is of type String
. Encoding contains the encoding information used in this rule. This attribute can raise a DOMException
with the values of NO_MODIFICATION_ALLOWED_ERR and SYNTAX_ERR.
Listing 13.6 demonstrates reading the encoding
property of the CSSCharsetRule
object.
<html>
<script language="JScript">
<!--
document.write(cssCharsetRuleObj.encoding);
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
DOM CSS Object.
The CSSFontFaceRule
object represents a set of font descriptions in a CSSStyleSheet
. CSSFontFaceRule
inherits all properties and methods from CSSRule
. The property associated with the CSSFontFaceRule
object is as follows:
Item | Description |
| This is a read-only property of type |
Listing 13.7 demonstrates manipulating the style
property of the CSSFontFaceRule
object.
<html>
<script language="JScript">
<!--
cssFontFaceRuleObj.style.face = "courier";
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssFontFaceRuleObj.style
This read-only attribute is of type CSSStyleDeclaration
. This attribute represents the declaration block of the rule.
Listing 13.8 demonstrates manipulating the style
property of the CSSFontFaceRule
object.
<html>
<script language="JScript">
<!--
cssFontFaceRuleObj.style.face = "ariel";
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
DOM CSS Object.
The CSSImportRule
object represents the @import rule of a CSSStyleSheet
. CSSImportRule
inherits all methods and properties of CSSRules
. Table 13.2 lists all properties of the CSSImportRule
object.
Listing 13.9 demonstrates reading the href
property of the CSSImportRule
object.
<html>
<script language="JScript">
<!--
document.writewrite(cssImportRuleObj.href);
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssImportRuleObj.href
The read-only property href
of the CSSImportRule
object is of type string
. The href
property is the textual representation of the location of the style sheet to be imported. The URI specifier won’t be included in this attribute.
Listing 13.10 demonstrates reading the href
property of the CSSImportRule
object.
<html>
<script language="JScript">
<!--
document.write(cssImportRuleObj.href);
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssImportRuleObj.media
The read-only property media of the CSSImportRule object is of type MediaList
. The media
property is a list of media types that can be used by the style sheet.
Listing 13.11 demonstrates reading the media
property of the CSSImportRule
object.
<html>
<script language="JScript">
<!--
document.write(cssImportRuleObj.media);
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssImportRuleObj.styleSheet
The read-only property styleSheet
of the CSSImportRule
object is of type CSSStyleSheet
. The styleSheet
property represents the loaded style sheet of this rule. If a style sheet hasn’t been loaded by this rule, the value will be Null.
Listing 13.12 demonstrates reading the styleSheet
property of the CSSImportRule
object.
<html>
<script language="JScript">
<!--
document.write(cssImportRuleObj.styleSheet);
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
DOM CSS Object.
The CSSMediaRule
object represents the target media types of a set of rules. CSSMediaRule
extends CSSRule
. Table 13.3 lists all methods and properties of the CSSMediaRule
object.
Listing 13.13 gets a CSSMediaRule
and sets its media type.
<html>
<script language="JScript">
<!--
mediaRuleObj.media = "screen";
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssMediaRuleObj.cssRules
The cssRule
property of the CSSMediaRule object is a read-only attribute of type CSSRuleList
. This is a list of CSS rules contained within the media block.
Listing 13.14 demonstrates iterating through the cssRules
property and processing each item.
<html>
<script language="JScript">
<!--
var ruleList = cssMediaRuleObj.cssRules;
var i = 0;
while( i < ruleList.length) {
processRule(ruleList.item(i);
i++;
}
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssMediaRuleObj.deleteRule(index)
The deleteRule()
method of the CSSMediaRule
takes the argument Number index. This method deletes the rule from the media block. This method can raise a DOMException
with the values of NO_MODIFICATION_ALLOWED_ERR and SYNTAX_ERR.
Listing 13.15 demonstrates removing a CSS media rule from the media block.
<html>
<script language="JScript">
<!--
cssMediaRule.deleteRule(1);
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssmediaRuleObj.insertRule(rule, index)
The insertRule()
method of the CSSMediaRule
object takes the arguments String rule and Number index and returns the index of the newly inserted rule. This method can raise a DOMException with the values of HIERARCHY_REQUEST_ERR, INDEX_SIZE_ERR, NO_MODIFICATION_ALLOWED_ERR, and SYNTAX_ERR.
Listing 13.16 illustrates inserting a rule into the media block.
<html>
<script language="JScript">
<!--
cssMediaRuleObj.insertRule("media:screen", 1);
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssMediaRuleObj.media
The media property of the CSSMediaRule
object is a read-only attribute of type MediaList
. This is a list of media types for this rule.
Listing 13.17 getting a CSSMediaRule
and setting its media type.
<html>
<script language="JScript">
<!--
mediaRuleObj.media = "handheld";
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
DOM CSS Object.
The CSSPageRule
object represents a @page rule within a CSSStyleSheet
. The CSSPageRule
extends CSSRule
. Table 13.4 lists all properties of the CSSPageRule
object.
Listing 13.18 demonstrates setting the selectorText
property of a CSSPageRule
object.
<html>
<script language="JScript">
<!--
cssPageRuleObj.selectorText = "some selector text";
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
CSSPageRule.selectorText
The selectorText
property of the CSSPageRule
object is a read-only attribute of type String
. The selectorText
property is a textual representation of the page selector. This attribute can raise a DOMException
with the values of NO_MODIFICATION_ ALLOWED_ERR and SYNTAX_ERR.
Listing 13.19 demonstrates setting the selectorText
property of a CSSPageRule
object.
<html>
<script language="JScript">
<!--
cssPageRuleObj.selectorText = "selection";
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssPageRuleObj.style
The style
property of the CSSPageRule object is a read-only attribute of type CSSStyleDeclaration
. The style
property represents the declaration block of this rule.
Listing 13.20 demonstrates manipulating the style
property of a CSSPageRule
object.
<html>
<script language="JScript">
<!--
cssPageRuleObj.style.size = "10";
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
DOM CSS Object.
The CSSPrimitiveValue
object represents a CSSValue
. This object can be used to determine or set a value for a specific style property. Table 13.5 lists all constants, properties, and methods of the CSSPrimitiveValue
object.
Listing 13.21 illustrates using the getRGBColor()
method of the CSSPrimitiveValue
object.
<html>
<script language="JScript">
<!--
var rgbColorObj = primitiveValObj.getRGBColor();
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssPrimitiveValueObj.getCounterValue()
The getCounterValue()
method of the CSSPrimitiveValue
takes no arguments and returns a Counter object representing the Counter value. This method can raise a DOMException
with the value of INVALID_ACCESS_ERR.
Listing 13.22 Getting a counter value for the CSSPrimitiveValue
object.
<html>
<script language="JScript">
<!--
var counterObj = cssPrimitiveValue.getCounterValue();
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssPrimitiveValueObj.getFloatValue(unitType)
The getFloatValue()
method of the CSSPrimitiveValue
takes the argument unitType and returns a float
value. This method can raise a DOMException
with the value of INVALID_ACCESS_ERR.
Listing 13.23 demonstrates the assigning of an event target and fires off an event.
<html>
<script language="JScript">
<!--
var floatVal = cssPrimitiveValue.getFloatValue
(CSSPrimitiveValue.CSS_PERCENTAGE);
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssPrimitiveValueObj.getRectValue()
The getRectValue()
method of the CSSPrimitiveValue
takes no arguments and returns a Rect
object representing a Rect
value. This method can raise a DOMException
with the value of INVALID_ACCESS_ERR.
Listing 13.24 Illustrates getting a Rect
value for the CSSPrimitiveValue
object.
<html>
<script language="JScript">
<!--
var rectObj = cssPrimitiveValue.getRectValue();
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssPrimitiveValueObj.getRGBColorValue()
The getRGBColorValue()
method of the CSSPrimitiveValue
takes no arguments and returns a RGBColor
object representing the RGB Color value. This method can raise a DOMException
with the value of INVALID_ACCESS_ERR.
Listing 13.25 illustrates using the getRGBColorValue()
method of the CSSPrimitiveValue
object.
<html>
<script language="JScript">
<!--
var rgbColorObj = primitiveValObj.getRGBColorValue();
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssPrimitiveValueObj.getStringValue()
The getStringValue()
method of the CSSPrimitiveValue
object takes no arguments and returns a String
value in the current unit. This method can raise a DOMException
with the value of INVALID_ACCESS_ERR.
Listing 13.26 Getting a string value for the CSSPrimitiveValue
object.
<html>
<script language="JScript">
<!--
var stringObj = cssPrimitiveValye.getStringValue();
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssPrimitiveValueObj.primitiveType
The primitiveType
property of the CSSPrimitiveValue
object is a read-only attribute of type Number
. The primitiveType
property is a Number
representing the type of value as defined by the constants.
Listing 13.27 demonstrates reading the primitiveType
property of the CSSPrimitiveValue
object.
<html>
<script language="JScript">
<!--
if(cssPrimitiveValObj.primitiveType == CSSPrimitiveValue.CSS_STRING)
processStringType(cssPrimitiveValObj.primitiveType);
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssPrimitiveValueObj.setFloatValue(unitType, floatType)
The setFloatValue()
method of the CSSPrimitiveValue
takes the arguments unitType and floatType and has no return value. This method can raise a DOMException
with the values of NO_MODIFICATION_ALLOWED_ERR and INVALID_ACCESS_ERR.
Listing 13.28 demonstrates setting a float value for CSSPrimitveValue
.
<html>
<script language="JScript">
<!--
cssPrimitiveValue.setFloatValue(CSSPrimitiveValue.CSS_PERCENTAGE, 3.34);
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssPrimitiveValueObj.setStringValue(stringType, stringValue)
The setStringValue()
method of the CSSPrimitiveValue
takes the arguments
stringType and stringValue and has no return value. This method can raise a DOMException
with the values of NO_MODIFICATION_ALLOWED_ERR and INVALID_ACCESS_ERR.
Listing 13.29 setting a string value for the CSSPrimitiveValue
object.
<html>
<script language="JScript">
<!--
cssPrimitiveValue.setStringValue
(CSSPrimitiveValue.CSS_STRING, "a random string");
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
DOM CSS Object.
CSSRule
is an abstract base object for any CSS statement including the rules set and at rules. Table 13.6 lists all the properties of the CSSRule
object.
Listing 13.30 illustrates getting a CSSRules
object and iterating through the list while checking each rule’s type.
<html>
<script language="JScript">
<!--
var ruleList = cssStyleSheetObj.rules;
var i = 0;
while( i < ruleList.length) {
var ruleObj = ruleList.index(i);
if(ruleObj.type == UNKNOWN_RULE)
handleUnknownRule(ruleObj);
i++;
}
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssRuleObj.cssText
The cssText property of the CSSRule object returns a string
. This is a textual representation of the CSS rule. This String holds the current state of the CSS rule. This attribute can raise a DOMException
with the values of HIERARCHY_REQUEST_ERR, NO_MODIFICATION_ALLOWED_ERR, INVALID_MODIFICATION_ERR, and SYNTAX_ERR.
Listing 13.31 illustates the setting of the cssText
property for a CSSRule
object.
<html>
<script language="JScript">
<!--cssRule.cssText = "color:'green'; font-weight:bold";
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssRuleObj.parentRule
The read-only property parentRule of the CSSRule object is of type CSSRule
. If this CSSRule
is contained within another CSSRule
, this is the containing rule. Otherwise this is Null.
Listing 13.32 demonstrates reading the parentRule
property.
<html>
<script language="JScript">
<!--
if(cssRuleObj.parentRule.name = "myfontrule")
processRule(cssRuleObj.parentRule);
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssRuleObj.parentStyleSheet
The read-only property parentStyleSheet
of the CSSRule
object is of type CSSStyleSheet
. Represents the style sheet that contains this rule.
Listing 13.33 demonstrates reading the parentStyleSheet
property.
<html>
<script language="JScript">
<!--
if(cssRuleObj.parentStyleSheet.name = "mycss")
processMyCSS(cssRuleObj.parentStyleSheet);
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssRuleObj.type
The read-only property type
of the CSSRule
object returns a number indicating the type of rule.
Listing 13.34 getting a CSSRules
object and iterating through the list while checking each rule’s type.
<html>
<script language="JScript">
<!--
var ruleList = cssStyleSheetObj.rules;
var i = 0;
while( i < ruleList.length) {
var ruleObj = ruleList.item(i);
if(ruleObj.type == MEDIA_RULE)
handleUnknownRule(ruleObj);
i++;
}
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
DOM CSS Object.
CSSRuleList
is an object that acts as an abstraction of an ordered collection of CSS Rules. Table 13.7 lists all properties and methods of the CSSRuleList
object.
Listing 13.35 getting a CSSRuleList
object and iterating through the list.
<html>
<script language="JScript">
<!--
var ruleList = cssStyleSheetObj.rules;
var i = 0;
while( i < ruleList.length) {
processRule(ruleList.item(i);
i++;
}
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssRuleListObj.item(
index
)
The item()
method of the CSSRuleList
takes the argument index. This method is used to retrieve the CSS rule by the ordinal index.
Listing 13.36 getting a CSSRuleList
object and iterating through the list.
<html>
<script language="JScript">
<!--
var ruleList = cssStyleSheetObj.rules;
var i = 0;
while( i < ruleList.length) {
processRule(ruleList.item(i));
i++;
}
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssRuleListObj.length
The length
property of the CSSRuleList
object returns the number of CSS rules contained within the CSSRuleList
.
Listing 13.37 getting a CSSRuleList
object and iterating through the list.
<html>
<script language="JScript">
<!--
var ruleList = cssStyleSheetObj.rules;
var i = 0;
while( i < ruleList.length) {
processRule(ruleList.item(i);
i++;
}
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
DOM CSS Object.
The CSSStyleDeclaration
object represents a CSS declaration block. CSSStyleDeclaration
can be used to set or determine what style properties are set within the block. Table 13.8 lists all properties and methods of the CSSStyleDeclaration
object.
Listing 13.38 demonstrates setting the CSSText
property of the CSSStyleDeclation
object.
<html>
<script language="JScript">
<!--
var cssStyleDeclarationObj = cssStyleSheetObj.cssRules.item(0);
cssStyleDeclarationObj.cssText = "color:'green'; font-weight:bold";
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssStyleDeclObj.cssText
The cssText
property of the CSSStyleDeclaration
object is a textual representation of the declaration block. Setting this attribute will reset all properties set in this declaration block. This attribute can raise a DOMException
with the values of NO_MODIFICATION_ALLOWED_ERR and SYNTAX_ERR.
Listing 13.39 demonstrates setting the cssText
property of CSSStyleDeclaration
object.
<html>
<script language="JScript">
<!--
var cssStyleDeclarationObj = cssStyleSheetObj.cssRules.item(0);
cssStyleDeclarationObj.cssText = "color:'red'; font-weight:bold";
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssStuleDeclObj.getPropertyCSSValue(propertyName)
The getPropertyCSSValue()
method of the CSSStyleDeclaration
takes the argument string propertyName and returns a CSSValue
representing the value of the property of the property that has been set. Returns Null if the property hasn’t been set.
Listing 13.40 illustrates getting a property value using the getPropertyCSSValue()
method of CSSStyleDeclaration
.
<html>
<script language="JScript">
<!--
var cssStyleDeclarationObj = cssStyleSheetObj.cssRules.item(0);
cssStyleDeclarationObj.getPropertyCSSValue("height");
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssStyleDecl.getPropertyPriority(
propertyName)
The getPropertyPriority()
method of the CSSStyleDeclaration
takes the argument propertyName and returns a String
representing the priority of the CSS property. Returns an empty string if none exists.
Listing 13.41 illustrates getting a property value using the getPropertyPriority()
method of CSSStyleDeclaration
.
<html>
<script language="JScript">
<!--
var cssStyleDeclarationObj = cssStyleSheetObj.cssRules.item(0);
cssStyleDeclarationObj.getPropertyPriority("height");
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssStyleDeclObj.getPropertyValue(
propertyName)
The getPropertyValue()
method of the CSSStyleDeclaration
takes the argument propertyName and returns a String
representing the value of the property in the declaration block. Returns an empty string
if the property hasn’t been set.
Listing 13.42 illustrates getting a property value using the getPropertyValue()
method of CSSStyleDeclaration
.
<html>
<script language="JScript">
<!--
var cssStyleDeclarationObj = cssStyleSheetObj.cssRules.item(0);
cssStyleDeclarationObj.getPropertyValue("height");
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssStyleDeclarationObj.item(
index)
The item()
method of the CSSStyleDeclaration
takes the argument index and returns a String
representing the name of the property at the ordinal position.
Listing 13.43 illustrates getting a CSSValue
and setting its value type.
<html>
<script language="JScript">
<!--
var cssStyleDeclarationObj = cssStyleSheetObj.cssRules.item(0);
var cssValueObj = cssStyleDeclarationObj.getPropertyCSSValue("height");
document.write(cssValueObj.cssValueType);
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssStyleDeclObj.length
The length
property of the CSSStyleDeclaration
object is a read-only attribute of type Number
. Length
is the number of properties that have been set in this declaration block.
Listing 13.44 illustrates reading the length
property of CSSStyleDeclaration
.
<html>
<script language="JScript">
<!--
var cssStyleDeclarationObj = cssStyleSheetObj.cssRules.item(0);
document.write(cssStyleDeclarationObj.length);
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssStyleDeclObj.parentRule
The parentRule read-only property of the CSSStyleDeclaration
object. The parentRule
property represents the CSSRule
that contains this declaration block or is Null if this block isn’t contained in a CSSRule
.
Listing 13.45 illustrates reading the parentRule
property of CSSStyleDeclaration
.
<html>
<script language="JScript">
<!--
var cssStyleDeclarationObj = cssStyleSheetObj.cssRules.item(0);
document.write(cssStyleDeclarationObj.parentRule);
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssStyleDeclObj.removeProperty(propertyName)
The removeProperty()
method of the CSSStyleDeclaration
takes the argument propertyName and returns a String
representing the value of the property that has been set. Returns an empty string if the property hasn’t been set. This method can raise a DOMException
with the value of NO_MODIFICATION_ALLOWED_ERR.
Listing 13.46 illustrates getting a property value using the removeProperty()
method of CSSStyleDeclaration
.
<html>
<script language="JScript">
<!--
var cssStyleDeclarationObj = cssStyleSheetObj.cssRules.item(0);
cssStyleDeclarationObj.removeProperty("height");
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssStyleDeclObj.setProperty(propertyName, value, priority)
The setProperty()
method of the CSSStyleDeclaration
takes the arguments string propertyName, string value, string priority, and has no return value. This method can raise a DOMException
with the value of NO_MODIFICATION_ALLOWED_ERR.
Listing 13.47 illustrates setting a property value using the setProperty()
method of CSSStyleDeclaration
.
<html>
<script language="JScript">
<!--
var cssStyleDeclarationObj = cssStyleSheetObj.cssRules.Item(0);
cssStyleDeclarationObj.setProperty("height", "35");
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
DOM CSS Object.
CSSStyleRule
is an object representing a single rule set in a CSSStyleSheet
. CSSStyleRule
extends CSSRule
. Table 13.9 lists all properties of the CSSStyleRule
object.
Listing 13.48 gets a CSSStyleRule
object and sets its selectorText
property.
<html>
<script language="JScript">
<!--
var cssStyleRuleObj = bodObj.style;
cssStyleRuleObj.selectorText = "some text";
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssStyleRuleObj.selectorText
The selectorText
of the CSSStyleRule
object is a read-only attribute of type string
. This is a textual representation of the selector of this rule set. This attribute can raise a DOMException
with the values of NO_MODIFICATION_ALLOWED_ERR and SYNTAX_ERR.
Listing 13.49 getting a CSSStyleRule
object and setting its selectorText
property.
<html>
<script language="JScript">
<!--
var cssStyleRuleObj = bodObj.style;
cssStyleRuleObj.selectorText = "selector text";
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssStyleRuleObj.style
The style property of the CSSStyleRule object is a read-only property of type CSSStyleDeclaration
. This contains the declarative block of the rule set.
Listing 13.50 demonstrates the assignment of a value to the height
property of the style
property of the CSSStyleRule
object.
<html>
<script language="JScript">
<!--
cssStyleRuleObj.style.height = 24;
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
DOM CSS Object.
The CSSStyleSheet
object is used to represent a CSS style sheet. This object allows access to the collection of rules within a CSS StyleSheet. Table 13.10 lists all properties and methods of the CSSStyleSheet
object.
Listing 13.51 demonstrates the creation of a CSSStyleSheetObject
.
<html>
<script language="JScript">
<!--
var cssStyleSheetObj = DOMImplementationCSS.createCSSStyleSheet
("mycss", "handheld");
// -->
</script>
</html>
JavaScript 1.5+,
JScript 5+ Nav6+, IE5+
cssStyleSheetObj.cssRules
The cssRules
property of the CSSStyleSheet
object is a read-only property that is of type CSSRuleList
object. cssRules
is a list of all rules contained within the style sheet and includes both rule sets
and at-rules
.
Listing 13.52 demonstrates iterating through the list of cssRules
and displaying the type of each.
<html>
<script language="JScript">
<!--
var rulesList = cssStyleSheetObj.cssRules;
var i = 0;
while(i < ruleList.length) {
display(ruleList.Index(i).type);
i++;
}
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssStyleSheetObj.deleteRule(index)
The deleteRule()
method of the CSSStyleSheet
takes the argument index
. This method is used to remove a rule from the style sheet at position index
. This method can raise a DOMException
with the values of INDEX_SIZE_ERR
and NO_MODIFICATION_ALLOWED_ERR.
Listing 13.53 demonstrates removing a CSSRule
from the stylesheet.
<html>
<script language="JScript">
<!--
cssStyleSheetObj.deleteRule(0);
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssStyleSheetObj.insertRule(rule, index)
The insertRule()
method of the CSSStyleSheet
takes the arguments rule
and index
and returns the index of the newly inserted rule. This method can raise a DOMException
object with the values of HIERARCHY_REQUEST_ERR, INDEX_SIZE_ERR, NO_MODIFICATION_ALLOWED_ERR,
and SYNTAX_ERR.
Listing 13.54 illustrates inserting a new CSSRule
into the style sheet.
<html>
<script language="JScript">
<!--
cssStyleSheetObj.insertRule("margin-top: 1ex", 0);
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssStyleSheetObj.ownerRule
This is a read-only attribute that is of type CSSRule
object. ownerRule
can contain both rule sets
and at-rules
.
Listing 13.55 demonstrates reading the ownerRule
property.
<html>
<script language="JScript">
<!--
if(cssStyleSheetObj.ownerRule.type = "Media") {
handleMediaRuler(cssStyleSheetObj.ownerRule);
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
DOM CSS Object.
The CSSUnknownRule
object represents an at-rule
that isn’t supported. It inherits all methods and properties from CSSRule
.
Listing 13.56 getting a CSSRules
object and iterating through the list while checking to see whether the rule type is a CSSUnknownRule
.
<html>
<script language="JScript">
<!--
var ruleList = cssStyleSheetObj.rules;
var i = 0;
while( i < ruleList.length) {
var ruleObj = ruleList.item(i);
if(ruleObj.Type == UNKNOWN_RULE)
handleUnknownRule(ruleObj);
i++;
}
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
DOM CSS Object.
The CSSValue
object represents a simple or complex value within the context of a CSS property. Table 13.11 lists all constants and properties of the CSSValue
object.
Listing 13.57 illustrates getting a CSSValue
and setting its value type.
<html>
<script language="JScript">
<!--
var cssStyleDeclarationObj = cssStyleSheetObj.cssRules.item(0);
var cssValueObj = cssStyleDeclarationObj.getPropertyCSSValue("height");
document.write(cssValueObj.cssValueType);
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssValueObj.cssText
The cssText
property of the CSSValue
object is of type string
. The cssText
property is a textual representation of the current value. This attribute can raise a DOMException
with the values of NO_MODIFICATION_ALLOWED_ERR, INVALID_MODIFICATION_ERROR
, and SYNTAX_ERR.
Listing 13.58 illustrates getting a CSSValue
and setting its value type.
<html>
<script language="JScript">
<!--
var cssStyleDeclarationObj = cssStyleSheetObj.cssRules.item(0);
var cssValueObj = cssStyleDeclarationObj.getPropertyCSSValue("height");
document.write(cssValueObj.cssText);
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssValueObj.cssValueType
The read-only property cssValueType
of the CSSValue
object is of type Number
. The cssValueType
property is a code defining the type of value.
Listing 13.59 illustrates getting a CSSValue
and setting its value type.
<html>
<script language="JScript">
<!--
var cssStyleDeclarationObj = cssStyleSheetObj.cssRules.item(0);
var cssValueObj = cssStyleDeclarationObj.getPropertyCSSValue("height");
document.write(cssValueObj.cssValueType);
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
DOM CSS Object.
The CSSValueList
object is an abstraction of an ordered collection of CSSValues
. Table 13.12 lists the property and method of the CSSValue
object.
Listing 13.60 illustrates iterating through a CSSValueList
object.
<html>
<script language="JScript">
<!--
var i = 0;
while(i < valueListObj.length) {
var listItem = valueListObj.item(i);
processListItem(listItem);
i++;
}
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssValueListObj.item(index)
The item()
method of the CSSValueList
takes the argument Number index
and returns the CSSValue
at the index position in the list.
Listing 13.61 illustrates iterating through a CSSValueList
object.
<html>
<script language="JScript">
<!--
var i = 0;
while(i < valueListObj.length) {
var listItem = valueListObj.item(i);
processListItem(listItem);
i++;
}
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
cssValueListObj.length
This read-only attribute is of type Number
. Length is a number representing the number of CSSValue
objects in the list.
Listing 13.62 illustrates iterating through a CSSValueList
object.
<html>
<script language="JScript">
<!--
var i = 0;
while(i < valueListObj.length) {
var listItem = valueListObj.item(i);
processListItem(listItem);
i++;
}
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
DOM CSS Object.
The DocumentCSS
object represents a document with a CSS view. The method associated with the DocumentCSS
object is as follows:
Item | Description |
| This method returns a |
Listing 13.63 demonstrates getting the overridden style of a particular element.
<html>
<script language="JScript">
<!--
documentCSSObj.getOverrideStyle(bodyObj, null);
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
documentCSSObj.getOverrideStyle(elt, pseudoElt)
The getOverrideStyle()
method of the DocumentCSS
takes the arguments Element elt
and String pseudoElt
and returns the override style declaration.
Listing 13.64 demonstrates getting the overridden style of a particular element.
<html>
<script language="JScript">
<!--
documentCSSObj.getOverrideStyle(tableObj, null);
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
DOM CSS Object.
The DOMImplementationCSS
object represents the ability for the DOM user to create a CSSStyleSheet
outside the context of the document. The method associated with the DOMImplementationCSS
object is as follows:
Item | Description |
| This method returns a |
Listing 13.65 demonstrates creating a new style sheet.
<html>
<script language="JScript">
<!--
var cssStyleSheetObj = DOMImplementation.createCSSStyleSheet("my css",
"print");
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
DOMImplementationCSS.createCSSStyleSheet(title, media)
The CreateCSSStyleSheet()
method of the DOMImplementationCSS
takes the arguments String title
and String media
and returns a new CSSStyleSheet
. This method can raise a DOMException
with the value of SYNTAX_ERR
.
Listing 13.66 demonstrates creating a new style sheet.
<html>
<script language="JScript">
<!--
var cssStyleSheetObj = DOMImplementation.createCSSStyleSheet("my css",
"print");
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
DOM CSS Object.
The ElementCSSInlineStyle
object represents the contents of the style attribute for HTML elements. The property associated with the ElementCSSInlineStyle
object is as follows:
Listing 13.67 demonstrates reading the style
property from the ElementCSSInlineStyle
object.
<html>
<script language="JScript">
<!--
var cssStyleDef = elementCSSInlineStyleObj.style;
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
elementCSSInlineStyleObj.style
The read-only property style
of the ElementCSSInlinestyle
object is of type CSSStyleDeclaration
.style
is a textual representation of the style for HTML elements.
Listing 13.68 demonstrates reading the style
property from the ElementCSSInlineStyle
object.
<html>
<script language="JScript">
<!--
var cssStyleDef = elementCSSInlineStyleObj.style;
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
DOM CSS Object.
The Rect object represents any Rect
value. Rect
reflects the values in the style
properties. Modifications in the style
properties are reflected in this object. Table 13.13 lists all properties of the Rect
object.
Listing 13.69 illustrates reading the properties of the Rect
object.
<html>
<script language="JScript">
<!--
var rectObj = primitiveValObj.getRectValue();
var topVal = rectObj.top;
var rightVal = rectObj.right;
var bottomVal = rectObj.bottom;
var leftVal = rectObj.left;
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
rectObj.bottom
The read-only property bottom
of the Rect
object is of type CSSPrimitiveValue
.bottom
represents the bottom of the Rect
.
Listing 13.70 illustrates reading the bottom
property of the Rect
object.
<html>
<script language="JScript">
<!--
var rectObj = primitiveValObj.getRectValue();
var bottomVal = rectObj.bottom;
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
Rect.left
The read-only property left
of the Rect
object is of type CSSPrimitiveValue
.Left
represents the left of the Rect
.
Listing 13.71 illustrates reading the left
property of the Rect
object.
<html>
<script language="JScript">
<!--
var rectObj = primitiveValObj.getRectValue();
var leftVal = rectObj.left;
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
Rect.right
The read-only property right
of the Rect
object is of type CSSPrimitiveValue
.Right
represents the right of the rectangle.
Listing 13.72 illustrates reading the right
property of the Rect
object.
<html>
<script language="JScript">
<!--
var rectObj = primitiveValObj.getRectValue();
var rightVal = rectObj.right;
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
Rect.top
The read-only property top
of the Rect
object is of type CSSPrimitiveValue
. The top
property represents the top of the Rect
.
Listing 13.73 illustrates reading the top property of the Rect
object.
<html>
<script language="JScript">
<!--
var rectObj = primitiveValObj.getRectValue();
var topVal = rectObj.top;
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
DOM CSS Object.
The RGBColor
object is a representation of any RGB color value. RGBColor
reflects the values in the style properties. Modifications in the style properties are reflected in this object. Table 13.14 lists all properties of the RGBColor
object.
Listing 13.74 illustrates the manipulation of the RGBColor
object.
<html>
<script language="JScript">
<!--
var rgbColorObj = primitiveValObj.getRGBColor();
var redVal = rgbColorObj.red;
var greenVal = rgbColorObj.green;
var blueVal = rgbColorObj.blue;
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
rgbColorObj.blue
The read-only property blue
of the RGBColor
object is of type CSSPrimitiveValue
. blue
is used to represent the blue value of the RGB color.
Listing 13.75 illustrates the manipulation of the RGBColor
object.
<html>
<script language="JScript">
<!--
var rgbColorObj = primitiveValObj.getRGBColor();
var blueVal = rgbColorObj.blue;
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
rgbColor.green
The read-only property green
of the RGBColor
object is of type CSSPrimitiveValue
. green
is used to represent the green value of the RGB color.
Listing 13.76 illustrates the manipulation of the RGBColor
object.
<html>
<script language="JScript">
<!--
var rgbColorObj = primitiveValObj.getRGBColor();
var greenVal = rgbColorObj.green;
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
rgbColor.red
The read-only property red
of the RGBColor
object is of type CSSPrimitiveValue
. Red
is used to represent the red value of the RGB color.
Listing 13.77 illustrates the manipulation of the RGBColor
object.
<html>
<script language="JScript">
<!--
var rgbColorObj = primitiveValObj.getRGBColor();
var redVal = rgbColorObj.red;
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
DOM CSS Object.
The ViewCSS
object represents a CSS view. The method associated with the ViewCSS
object is as follows:
Listing 13.78 demonstrates getting the computed style of a particular element.
<html>
<script language="JScript">
<!--
viewCSSObj.getComputerStyle(bodyObj, null);
// -->
</script>
</html>
JavaScript 1.5+, JScript 5+
Nav6+, IE5+
viewCSSObj.getComputedStyle(elt, pseudoElt)
The getComputedStyle()
method of the ViewCSS object takes the arguments Element elt and String pseudoElt and returns the computed style.
Listing 13.79 demonstrates getting the computed style of a particular element.
<html>
<script language="JScript">
<!--
viewCSSObj.getComputerStyle(tableObj, null);
// -->
</script>
18.222.115.120