CSSKeyframesRule: deleteRule() method
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since August 2016.
ThedeleteRule() method of theCSSKeyframeRule interface deletes theCSSKeyFrameRule that matches the specified keyframe selector.
In this article
Syntax
deleteRule(select)Parameters
selectA string which contains the keyframe selector of the rule to be deleted, which must be:
- a comma-separated list of percentage values between 0% and 100%;
- or, the keywords
fromorto
Note that the number and order of the values in the specified keyframe selector must match those of the targeted keyframe rule(s). White-space is disregarded.
Return value
None (undefined).
Examples
The CSS includes a keyframes at-rule. This will be the firstCSSRule returned bydocument.styleSheets[0].cssRules.myRules[0] returns aCSSKeyframesRule object. Returning thecssRules property would return aCSSRuleList containing two rules.
After deleting a rule withdeleteRule() thecssRules property returns aCSSRuleList containing one rule.
@keyframes slide-in { from { transform: translateX(0%); } to { transform: translateX(100%); }}let myRules = document.styleSheets[0].cssRules;let keyframes = myRules[0]; // a CSSKeyframesRulekeyframes.deleteRule("to");console.log(keyframes.cssRules); // a CSSRuleList object with one ruleSpecifications
| Specification |
|---|
| CSS Animations Level 1> # dom-csskeyframesrule-deleterule> |