From b0a5be89198e436d4feda95d8b42ad5dc67c2dc2 Mon Sep 17 00:00:00 2001 From: Maxwell Drake Date: Sun, 7 Apr 2024 22:34:31 +0000 Subject: [PATCH] Update 'frontend.js' --- frontend.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/frontend.js b/frontend.js index 4524e28..30c5dc5 100644 --- a/frontend.js +++ b/frontend.js @@ -3,7 +3,8 @@ // Licensed under Samuel Public License with <3 // Functions for commonly used elements -// get element by id + +// Get element by ID function getElementById(elementID) { return document.getElementById(elementID) } @@ -170,6 +171,23 @@ function createButton(elementID, text, attributes = {}) { 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 = {}) { for (const [name, value] of Object.entries(attributes)) { element.setAttribute(name, value);