A helper for `document.createElement()` that can be loaded into a script with `require`.
Versión del día
Este script no debería instalarse directamente. Es una biblioteca que utilizan otros scripts mediante la meta-directiva de inclusión // @require https://update.greasyfork.org/scripts/559372/1716505/create-element-helper.js
function tag(name) {
return {
elem: document.createElement(name),
id: function (value) {
this.elem.setAttribute('id', value)
return this
},
attr: function (name, value) {
this.elem.setAttribute(name, value)
return this
},
style: function (name, value) {
this.elem.style[name] = value
return this
},
cssClass: function (value) {
this.elem.classList.add(value)
return this
},
checked: function (value) {
this.elem.checked = !!value
return this
},
text: function (content) {
this.elem.textContent = content
return this
},
on: function (event, handler, options = {}) {
this.elem.addEventListener(event, handler, options)
return this
},
append: function (child) {
this.elem.appendChild(child.elem || child)
return this
},
create: function () {
return this.elem
},
}
}