diff --git a/snippets/createElement.md b/snippets/createElement.md new file mode 100644 index 000000000..f3cfa7cd8 --- /dev/null +++ b/snippets/createElement.md @@ -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( + `
+

Hello!

+
` +); +console.log(el.className); // 'container' +``` diff --git a/tag_database b/tag_database index 099c08007..aee8519c5 100644 --- a/tag_database +++ b/tag_database @@ -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