View difference between Paste ID: RS1FFrUR and 72Emk7wc
SHOW: | | - or go back to the newest paste.
1
function createElement(type, content, parentNode, id, classes, attributes){
2
  const htmlElement = document.createElement(type)
3
4
  if(content && type !== 'input'){
5
    htmlElement.textContent = content;
6
  }
7
8
  if(content && type === 'input'){
9
    htmlElement.value = content;
10
  }
11
12
  if(id){
13
    htmlElement.id = id;
14
  }
15
16
  if (classes){
17
    htmlElement.classList.add(...classes);
18
  }
19
20
  if (parentNode){
21
    parentNode.appendChild(htmlElement);
22
    }
23
24
  //{ src: 'link to img', href: 'link to site' }
25
  if (attributes){
26
    for (const key in attributes) {
27
      htmlElement.setAttribute(key, attributes[key]); 
28
    }
29
  } 
30
  return htmlElement
31
}