Javascript 删除html包装代码并仅在行包含内容时保留内容?

Javascript 删除html包装代码并仅在行包含内容时保留内容?,javascript,jquery,html,Javascript,Jquery,Html,有这么多行,看起来像: <div class="info"><ul><li><b><a href="http://www.domain1.com/10166/a-l-f/" title="ALF" target="_blank">ALF</a></b>[some text here]<a href="http://www.domain2.com/50367/DMS/" title=... blah blah

有这么多行,看起来像:

<div class="info"><ul><li><b><a href="http://www.domain1.com/10166/a-l-f/" title="ALF" target="_blank">ALF</a></b>[some text here]<a href="http://www.domain2.com/50367/DMS/" title=... blah blah blah
但它只会删除href标记,而不会删除整个a标记。 我想删除整个标签,只保留它的内容。 我也使用过这些代码,但没有发生任何事情,只有错误

$("a[href*="domain1"]").replaceWith(function () {
return $(this).text();
});
&

&


但还是什么都没发生

此处的选择器中存在语法错误:

$("a[href*="domain1"]").replaceWith(function () {
  return $(this).text();
});

如果不转义,字符串中不能有双引号。请尝试:
“a[href*=\“domain1\”]”
或对字符串使用单引号,
“a[href*=“domain1]”
。这应该行得通。

href
a
标记的一个属性,因此使用
removeAttr('href')
将只删除链接部分,而保留
a
标记本身。当您说要“删除整个标记,只保留其内容”时,您的意思是将其更改为
p
标记还是什么?第一个
contents().unwrap()方法有什么问题?是的,我成功了!问题似乎来自于我试图运行代码的Jquery版本。我已经尝试了,两个都返回:TypeError:$(…)。replaceWith不是function@Mostafa您正在运行哪个jQuery版本?
$('a[href*="domain1"]').contents().unwrap();
$("a:contains(domain1)").find("a.link").contents().unwrap();
$("a[href*="domain1"]").replaceWith(function () {
  return $(this).text();
});