A helper for `document.createElement()` that can be loaded into a script with `require`.
Od
Ovu skriptu ne treba izravno instalirati. To je biblioteka za druge skripte koje se uključuju u meta direktivu // @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
},
}
}