Add createElement

This commit is contained in:
atomiks
2018-01-06 03:21:44 +11:00
parent 6e610f15e7
commit f083c9564d
2 changed files with 24 additions and 0 deletions

23
snippets/createElement.md Normal file
View 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>`
);
```

View File

@ -20,6 +20,7 @@ compose:function
copyToClipboard:browser
countOccurrences:array
countVowels:string
createElement:browser
currentURL:browser
curry:function
deepFlatten:array