From 21e14f2c0cee6c4fb66f5cc1426ab7b283158188 Mon Sep 17 00:00:00 2001 From: nodemixaholic Date: Sun, 31 Mar 2024 21:51:39 +0000 Subject: [PATCH] Update 'frontend.js' --- frontend.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/frontend.js b/frontend.js index dbfbc96..422be7d 100644 --- a/frontend.js +++ b/frontend.js @@ -109,11 +109,21 @@ function createParagraph(elementID, text) { return elem } -function createBody() { - const element = document.createElement("body"); - element.id = "body"; - document.appendChild(element); - return element; +function initBody(bodyID) { + // Create a new body element with the desired id + const newBody = document.createElement("body"); + newBody.id = bodyID; + + // Get a reference to the existing body element (if any) + const oldBody = document.body; + + // Replace the existing body (if present) with the new one + if (oldBody) { + document.documentElement.replaceChild(newBody, oldBody); + } else { + // Simply append the new body if none exists + document.documentElement.appendChild(newBody); + } } function createButton(elementID, text, attributes = {}) {