methods for creating tags
This commit is contained in:
parent
8e0b2d874c
commit
08cf3333a8
39
main.js
39
main.js
@ -84,6 +84,45 @@
|
|||||||
|
|
||||||
let removedFilesLinks = []
|
let removedFilesLinks = []
|
||||||
|
|
||||||
|
class Tag {
|
||||||
|
static make(name, params) {
|
||||||
|
let element = document.createElement(name)
|
||||||
|
for (const [name, value] of Object.entries(params)) {
|
||||||
|
if (name == "on") {
|
||||||
|
for (const [event, listener] of Object.entries(value)) {
|
||||||
|
element.addEventListener(event, listener)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (name == "classes") {
|
||||||
|
element.classList.add(value.split(" "))
|
||||||
|
}
|
||||||
|
else if (name == "children") {
|
||||||
|
element.append(...value)
|
||||||
|
}
|
||||||
|
else
|
||||||
|
element[name] = value
|
||||||
|
}
|
||||||
|
|
||||||
|
return element
|
||||||
|
}
|
||||||
|
|
||||||
|
static div(params) {
|
||||||
|
return this.make("div", params)
|
||||||
|
}
|
||||||
|
|
||||||
|
static span(params) {
|
||||||
|
return this.make("span", params)
|
||||||
|
}
|
||||||
|
|
||||||
|
static button(params) {
|
||||||
|
return this.make("button", params)
|
||||||
|
}
|
||||||
|
|
||||||
|
static input(params) {
|
||||||
|
return this.make("input", params)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class Property {
|
class Property {
|
||||||
name
|
name
|
||||||
content
|
content
|
||||||
|
Loading…
Reference in New Issue
Block a user