A helper for `document.createElement()` that can be loaded into a script with `require`.
이 스크립트는 직접 설치하는 용도가 아닙니다. 다른 스크립트에서 메타 지시문 // @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
},
}
}