I was wondering if there is a way to just remove the <h2> element inside of an element with a particular class if that element doesn't have any other elements following it. For example if I have only the following:
HTML:
<div class="test">
<h2>Test</h2>
</h2>
I want to just remove the <h2>Test</h2> but keep the div element present.
jQuery:
$(".test").each(function() {
if($(this).children().length == 0) {
$(this).remove();
}
});