HTML:
<p><br style="clear:both;"></p>
プロジェクトにウィキペディア API を使用しており、ウィキペディアの生の HTML 出力をクリーンアップしており、この問題に苦労しています。<p>
jQueryを使用してDOMからこの特定の要素を削除するにはどうすればよい.remove();
ですか? 内部にある<p>
要素のみを削除したい。<br style="clear:both;">
前もって感謝します!私はこの問題に苦労してきました。
HTML:
<p><br style="clear:both;"></p>
プロジェクトにウィキペディア API を使用しており、ウィキペディアの生の HTML 出力をクリーンアップしており、この問題に苦労しています。<p>
jQueryを使用してDOMからこの特定の要素を削除するにはどうすればよい.remove();
ですか? 内部にある<p>
要素のみを削除したい。<br style="clear:both;">
前もって感謝します!私はこの問題に苦労してきました。
So, you're trying to remove all elements that directly contain a <br>
with the given style attribute?
$('br[style="clear:both;"]').parent().remove();
This is decently conservative in that it only matches br
tags of the form you describe—though it might be worth being even more conservative by sticking a p
selector in that parent
call. But, it's also sufficiently conservative that it might not catch small variations on this markup, so keep an eye out.
子がそれ自体であると仮定するとbr
、コードは次のようになります -
$('p>br').closest('p').remove();
または使用
$('p>br[style="clear:both;"]').closest('p').remove();
または親関数を使用します
$('br[style="clear:both;"]').parent('p').remove();
しかし、それをしないでください
$('br[style="clear:both;"]').parent().remove(); // Don't use this
親がそうでないには多くのbr
可能性があるためdom
p
$('p').filter(function(i) {
return $(this).children('br').css('clear') == 'both';
}).remove();
$('p').each(function(){
if($(this).children('br').length == 1) {
$(this).remove();
}
});
これは私にとってはうまくいきました。「クリア:両方;」のようです。ブラウザによって生成されました。私がこれを理解できるように、すべてのアイデアと提案をありがとう!