I want to remove the temporary element which is created dynamically.
x = document.createElement("DIV");
x.innerHTML = res;
y = x.parentNode;
x = y.removeChild(x);
x = null;
I’ve written those codes but since it does note have a parent, they dont work. I know i can create a second temp node to keep first one but then i need a third node to delete the second one…. 🙂 Here i need a function to delete the node without needing a parent node. I also think that i can put the node to directly to document object and delete it, but i’m looking for more efficient solutions if exists.
You need not remove the node, since it is not added to the DOM. When you set the variable to
null, the element will cease to exist. In general, DOM nodes will always have a parent, provided they’re added to the model, but here you don’t do that in your code.