Search code examples
javascriptjqueryhtmltubepress

Use jQuery to remove a <p> with an empty <span> tag


I'm working on a Wordpress build using the Tubepress plug-in. This plug-in inserts an unwanted <p> above the video content. I'd like to remove this tag using jQuery.

Here's the code I'd like to remove:

<p><span id="more-76"></span></p>

The span id is auto-generated and will be different for each piece of content. This code is placed in the following div.

<div class="work1alt">
   <p><span id="more-76"></span></p>
</div>

Thanks in advance for help.


Solution

  • Like this:

    $('span:empty:only-child').parent('p').remove();
    

    This will be extremely fast, but will not select <span>s with whitespace in them.