Delete parent div, javascript

Hello everyone, I am trying to make a function that will delete its parent div without using jquery.

document.addEventListener("click", (e) => {
      if (e.target.classList.contains("xbutton")) {
       
      
        e.parentNode.removeChild(e.parentNode);

        
      }
    });

This is what I came up with , and it’s going redscreen as soon as I click it.
In case you need the seen the full page:

Thanks in advance for your help.