Update 'frontend.js'
This commit is contained in:
parent
fc9d73071d
commit
b0a5be8919
1 changed files with 19 additions and 1 deletions
20
frontend.js
20
frontend.js
|
@ -3,7 +3,8 @@
|
||||||
// Licensed under Samuel Public License with <3
|
// Licensed under Samuel Public License with <3
|
||||||
|
|
||||||
// Functions for commonly used elements
|
// Functions for commonly used elements
|
||||||
// get element by id
|
|
||||||
|
// Get element by ID
|
||||||
function getElementById(elementID) {
|
function getElementById(elementID) {
|
||||||
return document.getElementById(elementID)
|
return document.getElementById(elementID)
|
||||||
}
|
}
|
||||||
|
@ -170,6 +171,23 @@ function createButton(elementID, text, attributes = {}) {
|
||||||
return elem;
|
return elem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Insert element with ID to element with ID
|
||||||
|
function insertElementIntoId(elementIdOuter, elementIdSelf, tagName) {
|
||||||
|
const element = document.createElement(tagName);
|
||||||
|
element.id = elementIdSelf;
|
||||||
|
for (const [name, value] of Object.entries(attributes)) {
|
||||||
|
element.setAttribute(name, value);
|
||||||
|
}
|
||||||
|
getElementById(elementIdOuter).appendChild(element);
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert HTML to element with ID
|
||||||
|
function insertHTMLIntoId(elementIdOuter, html) {
|
||||||
|
getElementById(elementIdOuter).innerHTML = `${String(html)}`;
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
function changeAttributes(element, attributes = {}) {
|
function changeAttributes(element, attributes = {}) {
|
||||||
for (const [name, value] of Object.entries(attributes)) {
|
for (const [name, value] of Object.entries(attributes)) {
|
||||||
element.setAttribute(name, value);
|
element.setAttribute(name, value);
|
||||||
|
|
Loading…
Reference in a new issue