使用jquery删除重复的文本

使用jquery删除重复的文本,jquery,Jquery,假设我有以下几点 <h3>This is my heading</h3> <p>This is my headingAnd this is part of a paragraph</p> <h3>This is my heading</h3> <p>And this is part of a paragraph...</p> 但是因为这一段中有两个词连在一起,所以不起作用。数据是从rss提

假设我有以下几点

 <h3>This is my heading</h3>
 <p>This is my headingAnd this is part of a paragraph</p>
 <h3>This is my heading</h3>
 <p>And this is part of a paragraph...</p>
但是因为这一段中有两个词连在一起,所以不起作用。数据是从rss提要中动态提取的


提前感谢

如果您的DOM结构仍保持上述状态,则以下内容将适用于您:

$('p').text(function(index, oldText) {
  return oldText.replace($(this).prev('h1').text(), '');
});

根据你的评论

启动积极生活影响清单
从测试中启动活动生活影响检查表


企业计算会议 企业计算会议企业计算领域的世界领先者参加了为期两天的会议


$('p').text(函数(索引,oldText){ 返回oldText.replace($(this.prev('h3').text(),''); });


谢谢,我应该提到的是,有不止一个部分duplication@NickP不管它是否有更多的部分,只要将evety
h1
放在
p
之前,它就可以工作了。谢谢你的代码悖论,它的工作原理和我想要的完全一样。
$('p').text(function(index, oldText) {
  return oldText.replace($(this).prev('h1').text(), '');
});
<div id="youtube">
    <section>
        <h3>Launch of the Active Living impact checklist</h3>
        <p>Launch of the Active Living impact checklistFrom test</p>
        <a target="_blank" href="#"> watch video</a> <br>
    </section>
    <section>
        <h3>Enterprise Computing Conference</h3>
        <p>Enterprise Computing ConferenceWorld leaders in enterprise computing attended a two</p>
        <a target="_blank" href="#"> watch video</a> <br>
    </section>
</div>

$('p').text(function(index, oldText) {
  return oldText.replace($(this).prev('h3').text(), '');
});
var header = ​$('h1').​​​​text();
var body = $('p').text();

if (body.indexOf(header) >= 0) {
    $('p').text(body.replace(header, ''));
}