JSFiddle - React, Tailwind, and code Playground
by mlms13
JavaScript
var $dom = {
create: function (tag, attributes) {
var el = document.createElement(tag),
attr,
i;
window.a = arguments;
// Add all attributes to the element
if ((typeof attributes).toLowerCase() === 'string') {
el.className = attributes;
} else {
for (attr in attributes) {
if (attributes.hasOwnProperty(attr)) {
el.setAttribute(attr, attributes[attr]);
}
}
}
// Append child elements and text nodes
for (i = 0; i < args.length; i++) {
if (typeof HTMLElement === "object" ? args[i] instanceof HTMLElement : //DOM2
args[i] && typeof args[i] === "object" && args[i].nodeType === 1 && typeof args[i].nodeName==="string") {
el.appendChild(args[i]);
} else {
el.appendChild(document.createTextNode(args[i]));
}
}
}
};
document.body.appendChild($dom.create('h1', null, 'Test'));