Update snippet descriptions

This commit is contained in:
Isabelle Viktoria Maciohsek
2020-10-20 23:02:01 +03:00
parent 52880f08ee
commit caa67e2a49
63 changed files with 175 additions and 126 deletions

View File

@ -3,10 +3,11 @@ title: injectCSS
tags: browser,css,intermediate
---
Injects the given css code into the current document
Injects the given CSS code into the current document
- Use `Document.createElement()` to create a new `style` element and set its type to `text/css`.
- Use `Element.innerText` to set the value to the given css string, `Document.head` and `Element.appendChild()` to append the new element to the document head.
- Use `Element.innerText` to set the value to the given CSS string.
- Use `Document.head` and `Element.appendChild()` to append the new element to the document head.
- Return the newly created `style` element.
```js
@ -20,5 +21,6 @@ const injectCSS = css => {
```
```js
injectCSS('body { background-color: #000 }'); // '<style type="text/css">body { background-color: #000 }</style>'
injectCSS('body { background-color: #000 }');
// '<style type="text/css">body { background-color: #000 }</style>'
```