Fix jumping up when a question is answered

This commit is contained in:
Pieter Vander Vennet 2023-01-06 04:16:32 +01:00
parent 7f6611f9d5
commit 6cb5ced361

View file

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