var uls = document.getElementsByTagName('ul'); for (var i=uls.length-1; i>=0; i--) { if (uls[i].innerHTML.search('li') == -1) uls[i].parentNode.removeChild(uls[i]); }