JSFiddle - React, Tailwind, and code Playground
HTML
<div id="test">1</div>
<div id="foo">2</div>
<div id="bar12">3</div>
<div id="foobar">4</div>
CSS
table {
border: 1px solid black;
}
JavaScript
var divs = document.getElementsByTagName('div'),
forEach = Array.prototype.forEach,
regex = /^foo.*$/;
forEach.call(divs, function (d) {
if (d.id !== undefined && regex.test(d.id)) {
d.parentNode.removeChild(d);
}
});