Name
CSSStyleDeclaration.setProperty( ) — set a CSS style attribute
Availability
DOM Level 2 CSS
Synopsis
void setProperty(StringpropertyName, Stringvalue, Stringpriority) 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.