1

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.

4

4 に答える 4

7

このような:

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

これは非常に高速ですが、<span>空白を含む を選択しません。

于 2010-11-29T00:36:25.923 に答える
1
$('div.work1alt').find('p span:empty').parent().remove();
于 2010-11-29T00:36:41.600 に答える
1

最初の if 条件は、私が信じる子またはコンテンツがないかどうかを確認します。2 番目は、スパンに空のテキストが含まれているかどうかを確認し、スパン内のテキストのみを返しますが、子は返しません。

エレガントではなく、おそらく slak のソリューションほど高速ではありませんが、非常に明示的です。

 $('div.work1alt > p span').each(function(){
    if($.trim($(this).text()) === ""){
       $(this).parent().remove();
    }
 });

編集: '===""' を ifs に入れるのを忘れていました (doh!)

于 2010-11-29T00:59:07.607 に答える
-1

あなたのページに何が立っているかによって異なります。多分あなたはこれをそのように試しみるべきです$('p').remove();

于 2010-11-29T00:45:10.757 に答える