Update 'frontend.js'

This commit is contained in:
Maxwell Drake 2024-04-07 22:34:31 +00:00
parent fc9d73071d
commit b0a5be8919

View file

@ -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);