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.
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.
Share Improve this question edited Jan 28, 2013 at 18:48 eykanal 27.1k19 gold badges85 silver badges114 bronze badges asked Nov 29, 2010 at 0:31 scout75scout75 371 silver badge8 bronze badges 1- I realized about an hour after I posted this that the "MORE" tag within the editor was inserting this text at the top of the_content(). I no longer needed to use the "MORE" tag, so this solved the problem. I apologize for not posting this sooner, but appreciate the different approaches listed below. I'll now know what to do if I run into this problem in the future. Thank you. – scout75 Commented Nov 30, 2010 at 4:20
4 Answers
Reset to default 8Like this:
$('span:empty:only-child').parent('p').remove();
This will be extremely fast, but will not select <span>
s with whitespace in them.
$('div.work1alt').find('p span:empty').parent().remove();
The first if condition checks if there is no children or content I believe. The second checks if the span contains empty text and will return only text within the span, but not it's children.
Not as elegant and probably not as fast as slak's solution, but is very explicit.
$('div.work1alt > p span').each(function(){
if($.trim($(this).text()) === ""){
$(this).parent().remove();
}
});
EDIT: forgot to put the '===""' in the ifs (doh!)
depends on what else stands on your page. Maybe you should try this like that $('p').remove();