Seeking a solution for appending a span element to the DOM.
if (check something...) {
const newSpan = createElement('span');
newSpan.id = '_span';
const container = document.getElementById('container');
container.appendChild(newSpan);
}
How can I prevent duplicating the same element in the DOM tree within the "if" statement? It's like opening a window but avoiding re-adding it until it has been closed.