← Back to CSS domain
CSS.addRule
Inserts a new rule with the given `ruleText` in a stylesheet with given `styleSheetId`, at the
position specified by `location`.
Domain: CSS
experimental
Parameters
| Name | Type | Description |
styleSheetId | DOM.StyleSheetId | The css style sheet identifier where a new rule should be inserted. |
ruleText | string | The text of a new rule. |
location | SourceRange | Text position of a new rule in the target style sheet. |
nodeForPropertySyntaxValidation (optional) | DOM.NodeId | NodeId for the DOM node in whose context custom property declarations for registered properties should be
validated. If omitted, declarations in the new rule text can only be validated statically, which may produce
incorrect results if the declaration contains a var() for example. |
Returns
| Name | Type | Description |
rule | CSSRule | The newly created rule. |
Example Request
{
"id": 1,
"method": "CSS.addRule",
"params": {
"styleSheetId": "styleSheetId-value",
"ruleText": "ruleText-value",
"location": "location-value"
}
}
Example Response
{
"id": 1,
"result": {
"rule": "rule-value"
}
}
Usage in Node.js
const result = await send('CSS.addRule', {"styleSheetId": "styleSheetId-value", "ruleText": "ruleText-value", "location": "location-value"});
console.log(result);
// {"rule": "rule-value"}