Add createElement
This commit is contained in:
23
snippets/createElement.md
Normal file
23
snippets/createElement.md
Normal file
@ -0,0 +1,23 @@
|
||||
### createElement
|
||||
|
||||
Creates an element from a string.
|
||||
|
||||
Use `document.createElement()` to create a new element. Set its `innerHTML`
|
||||
to the string supplied as the argument. Use `ParentNode.firstElementChild` to
|
||||
return the element version of the string.
|
||||
|
||||
```js
|
||||
const createElement = str => {
|
||||
const el = document.createElement('div');
|
||||
el.innerHTML = str;
|
||||
return el.firstElementChild;
|
||||
};
|
||||
```
|
||||
|
||||
```js
|
||||
createElement(
|
||||
`<div class="container">
|
||||
<p>Hello!</p>
|
||||
</div>`
|
||||
);
|
||||
```
|
||||
@ -20,6 +20,7 @@ compose:function
|
||||
copyToClipboard:browser
|
||||
countOccurrences:array
|
||||
countVowels:string
|
||||
createElement:browser
|
||||
currentURL:browser
|
||||
curry:function
|
||||
deepFlatten:array
|
||||
|
||||
Reference in New Issue
Block a user