This is different from Remove dom element without knowing its parent?, because their element does have a parentNode.
I know how to remove an element through its parentNode, but if I create a new element, it doesn't have a parentNode at all.
So,
a) How can I remove this element?
b) Do I even need to? Or is it cleaned up as soon as the last reference to it is gone?
The context: I'm trying to write some automated tests for my JavaScript code. I'm using Mocha from the browser, and I want to test if child elements are inserted into a given parent. I create the parent on the fly before each test, but thought I shouldn't have to add it to the document. But I want to make sure that I got no big list of unreferenced nodes hanging around.
var element = document.createElement('div');
console.log(element); // The div
console.log(element.parentNode); // null
element.parentNode.removeChild(element); // "Cannot read property 'removeChild' of null"