A helper for `document.createElement()` that can be loaded into a script with `require`.
À partir de
Ce script ne devrait pas être installé directement. C'est une librairie créée pour d'autres scripts. Elle doit être inclus avec la commande // @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
},
}
}