I am currently attempting to identify any h2 element within a specific div that contains no content and then delete it. Below is the HTML code I am working with:
<div class="skipToContainer">
<h2 class="vidSkipTo">Hello </h2>
<h2 class="vidSkipTo"></h2>
<h2 class="vidSkipTo"></h2>
<h2 class="vidSkipTo"></h2>
</div>
Here are some jQuery snippets I have tested but they have not been successful:
jQuery(".skipToContainer .vidSkipTo").each (function () {
if (jQuery(this).text().trim() === '')
jQuery(this).remove();
}
jQuery(".skipToContainer h2").each (function () {
if (jQuery(this).text().trim() === '')
jQuery(this).remove();
}
jQuery(".skipToContainer h2").each (function () {
if (jQuery(this).text() === '')
jQuery(this).remove();
}
Any advice or suggestions on this issue?
Please note: These tests are being conducted on a local WordPress site. Not sure if that impacts the outcome, just providing additional context.