add a method to remove style property

I think it's not bad to introduce removeProperty() method :)
This commit is contained in:
Fardin 2022-06-06 20:08:59 +04:30 committed by GitHub
parent 291b5c05b9
commit 0ece900f50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -128,6 +128,14 @@ setTimeout(() => document.body.style.display = "", 1000); // back to normal
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.
Also there is a special method for that, `elem.style.removeProperty('style property')`. So, We can remove a property like this:
```js run
document.body.style.background = 'red'; //set background to red
setTimeout(() => document.body.style.removeProperty('background')); // remove background after 1 second
```
````smart header="Full rewrite with `style.cssText`"
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.