Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2020
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. export default function createElement(type, content, attributes) {
  2.     const result = document.createElement(type);
  3.  
  4.     if (attributes !== undefined) {
  5.         Object.assign(result, attributes);
  6.     }
  7.  
  8.     if (Array.isArray(content)) {
  9.         content.forEach(append);
  10.     } else if(content !== null || content !== undefined){
  11.         append(content);
  12.     }
  13.  
  14.     function append(node) {
  15.         if (typeof node === 'string' || typeof node === 'number') {
  16.             node = document.createTextNode(node);
  17.         }
  18.  
  19.         result.appendChild(node);
  20.     }
  21.  
  22.     return result;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement