使用jquery删除超链接中的标签 [英] remove tags inside hyperlink using jquery

查看:93
本文介绍了使用jquery删除超链接中的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



 < td我试图从这个超链接中删除span标签(自动生成,我无法删除它们):

类= MyClassID >
< a href =test.asp?showdetail =& ID =< span> 12< / span>>测试< / a>
< / td>

我的查询:

  $( MyClassID )找到( 跨度)的内容()解开()。; 

无法工作...有人可以帮我吗?
< DIV类= h2_lin>解决方案

小提琴演示

  $(。MyClassID a)。attr('href',function(_,old){
return old.replace('< span>','').replace('< / span>','');
});



问题 span 标记未预设在 .MyClassID



span 位于 a 标记的 href 属性中。



变化替换 <跨度> < /跨度> with empty string



.attr(attributeName,function(index,attr))


I try to remove the span tag (auto generated, I cannot remove them) from this hyperlink:

<td class="MyClassID">
   <a href="test.asp?showdetail=&ID=<span>12</span>">test</a>
</td>

My query:

$(".MyClassID").find("span").contents().unwrap();

Won't work... Can someone help me?

解决方案

Fiddle Demo

$(".MyClassID a").attr('href', function (_, old) {
    return old.replace('<span>', '').replace('</span>', '');
});


Problem span tag is not preset in .MyClassID

span is inside the href attribute of a tag.

change replace <span> and </span> with empty string

.attr( attributeName, function(index, attr) )

这篇关于使用jquery删除超链接中的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆