var container = document.getElementById("container"); var elements = container.getElementsByClassName("deleteme"); while (elements[0]) { elements[0].parentNode.removeChild(elements[0]); }