使用jQuery在超链接内的文本中添加一个span标记 [英] Add a span tag to text inside a hyperlink, using jQuery

查看:523
本文介绍了使用jQuery在超链接内的文本中添加一个span标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在超链接内的文本中添加一个span标记?

How would you add a span tag to the text inside a hyperlink?

现在,我正在使用以下方法将现有文本更改为其他内容:

Right now, I'm changing the existing text to something else, using this:

$(document).ready(function() {
$("a:contains('text')").text('new-text')
});

我需要链接在解析后看起来像这样:

I need the link to look like this when it is parsed:

<a href="/xxx.aspx">new-text<span class="someclass">some other text</span></a>

所以我需要在

有什么想法吗?

推荐答案

$("a:contains('text')")
    .text('new-text')
    .append($('<span></span>')
        .addClass('someclass')
        .text('some other text')
    )
;

这篇关于使用jQuery在超链接内的文本中添加一个span标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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