Merge pull request #3038 from webFardin/master

add a method to remove style property
This commit is contained in:
Ilya Kantor 2022-06-13 08:01:31 +02:00 committed by GitHub
commit 099881de79
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.