I am trying to hide the following element in an automatically generated HTML document:
Here is my solution which I just implemented for a client using jQuery 1.5.x - you might have to adjust the //skip empty tags but which are valid
regular expression string.
$('*:only-child:empty').each(
function(index) {
var currentElement = $(this);
// skip singleton tags
if(/^(?:area|br|col|embed|hr|img|input|link|meta|param)$/i.test(currentElement.get(0).tagName) == true) {
return
}
// skip empty tags but which are valid
if(/^(?:textarea)$/i.test(currentElement.get(0).tagName) == true) {
return
}
while (currentElement.parent().children().length == 1) {
currentElement = currentElement.parent();
}
// so 0 or more children for the parent then we hide it
// we will never have more then 0 children though the :empty takes care of that
console.log('hidding: ' + currentElement);
currentElement.hide()
}
);