This causes an error:
document.querySelector('#element-that-does-not-exist').remove()
The way I fix it:
let el = document.querySelector('#element-that-does-not-exist')
if (el) {
el.remove()
}
My question – is there a more elegant way to prevent an error? One line of code preferably?