Merge pull request #501 from atomiks/createElement
[FEATURE] createElement
This commit is contained in:
24
snippets/createElement.md
Normal file
24
snippets/createElement.md
Normal 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'
|
||||
```
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user