Update snippet descriptions
This commit is contained in:
@ -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>'
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user