Merge pull request #501 from atomiks/createElement

[FEATURE] createElement
This commit is contained in:
atomiks
2018-01-06 21:28:44 +11:00
committed by GitHub
2 changed files with 25 additions and 0 deletions

24
snippets/createElement.md Normal file
View File

@ -0,0 +1,24 @@
### 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
const el = createElement(
`<div class="container">
<p>Hello!</p>
</div>`
);
console.log(el.className); // 'container'
```

View File

@ -19,6 +19,7 @@ compose:function
copyToClipboard:browser,string,advanced
countOccurrences:array
countVowels:string
createElement:browser,utility
currentURL:browser,url
curry:function,recursion
deepFlatten:array,recursion