From 6cb5ced361867fac2ab6b01f6274ac8f2508975a Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Fri, 6 Jan 2023 04:16:32 +0100 Subject: [PATCH] Fix jumping up when a question is answered --- UI/BaseUIElement.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/UI/BaseUIElement.ts b/UI/BaseUIElement.ts index cc5e1ad90c..218be172ba 100644 --- a/UI/BaseUIElement.ts +++ b/UI/BaseUIElement.ts @@ -31,13 +31,19 @@ export default abstract class BaseUIElement { throw "SEVERE: could not attach UIElement to " + divId } - while (element.firstChild) { - //The list is LIVE so it will re-index each call - element.removeChild(element.firstChild) + let alreadyThere = false + const elementToAdd = this.ConstructElement() + const childs = Array.from(element.childNodes) + for (const child of childs) { + if (child === elementToAdd) { + alreadyThere = true + continue + } + element.removeChild(child) } - const el = this.ConstructElement() - if (el !== undefined) { - element.appendChild(el) + + if (elementToAdd !== undefined && !alreadyThere) { + element.appendChild(elementToAdd) } return this