I am dynamically generating a table and after that I want to append it as a child to a div. The problem is every time i regenerate the table it gets appended in the same div without the old table removed.
if(context.children.length == 0){
context.appendChild(table);
}else{
context.replaceChild(table);
}
I tried with checking if the child already exists and if it does i replace it with the new element.
But I get the error The argument is not optional and I don't know how to do it otherwise. Any ideas?
replaceChildmethod should have 2 args .... new and old child