First you need to declare a method to remove the element by its ID:
Element.prototype.remove = function() {
this.parentElement.removeChild(this);
}
NodeList.prototype.remove = HTMLCollection.prototype.remove = function() {
for(var i = this.length - 1; i >= 0; i--) {
if(this[i] && this[i].parentElement) {
this[i].parentElement.removeChild(this[i]);
}
}
}
And then, assuming your table has the ID minha-tabela
, you can remove it with:
document.getElementById("minha-tabela").remove();
Or else select her by some class:
document.getElementsByClassName("table-sm").remove();
As an alternative to all of the above, you can also reset the HTML of the element:
document.getElementById("minha-tabela").outerHTML = "";
Source of this question.