36 lines
762 B
JavaScript
36 lines
762 B
JavaScript
function Dom() {
|
|
return {
|
|
clear: clear,
|
|
make: make
|
|
}
|
|
|
|
function clear(elem) {
|
|
while(elem.firstChild) {
|
|
elem.removeChild(elem.firstChild);
|
|
}
|
|
}
|
|
|
|
function make(tag, properties, children) {
|
|
var e = document.createElement(tag);
|
|
properties = properties || {};
|
|
children = children || [];
|
|
for(key in properties) {
|
|
var value = properties[key];
|
|
switch(key) {
|
|
case "class":
|
|
e.className = Array.isArray(value) ? value.join(' ') : value;
|
|
break;;
|
|
case "onClick":
|
|
e.addEventListener("click", value);
|
|
break;;
|
|
default:
|
|
e[key] = value;
|
|
}
|
|
}
|
|
for(var i = 0; i < children.length; i++) {
|
|
e.appendChild(children[i]);
|
|
}
|
|
return e;
|
|
}
|
|
|
|
}
|