Name
addRule( ) — NN n/a IE 4 DOM n/a
Synopsis
addRule(selector,
style, [index])
Adds a new rule for a style sheet. This method offers a scripted way
of adding a rule to an existing styleSheet object:
document.styleSheets[1].addRule("P B","color:red")You may duplicate a selector that already exists in the
styleSheet and, therefore, override an existing
rule for the same element selector. The only prohibition is that you
may not override a rule to convert a plain style rule into one that
creates a positionable element. The new rule is governed by the same
cascading rules as all style sheet rules (that includes the
rule’s source code position among other rules with the same
selector). Therefore, a new rule in a styleSheet
object does not supersede a style set in an element’s
STYLE property.
Returned Value
None.
Parameters
-
selector The style rule selector as a string.
-
style One or more style attribute:value pairs. Multiple pairs are semicolon delimited, just as they are in the regular style sheet definition.
-
index An optional integer indicating where in the collection the new element should be placed.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access