Skip to content

Commit 0ece900

Browse files
author
Fardin
authored
add a method to remove style property
I think it's not bad to introduce removeProperty() method :)
1 parent 291b5c0 commit 0ece900

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

2-ui/1-document/08-styles-and-classes/article.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@ setTimeout(() => document.body.style.display = "", 1000); // back to normal
128128

129129
If we set `style.display` to an empty string, then the browser applies CSS classes and its built-in styles normally, as if there were no such `style.display` property at all.
130130

131+
Also there is a special method for that, `elem.style.removeProperty('style property')`. So, We can remove a property like this:
132+
133+
```js run
134+
document.body.style.background = 'red'; //set background to red
135+
136+
setTimeout(() => document.body.style.removeProperty('background')); // remove background after 1 second
137+
```
138+
131139
````smart header="Full rewrite with `style.cssText`"
132140
Normally, we use `style.*` to assign individual style properties. We can't set the full style like `div.style="color: red; width: 100px"`, because `div.style` is an object, and it's read-only.
133141

0 commit comments

Comments
 (0)