开发者

Add a span tag to text inside a hyperlink, using jQuery

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

Right now, I'm chang开发者_如何学Going 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>

So I need to add that span tag inside the

Any ideas?


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


you can use html() method to add a markup:

$(document).ready(function() {
    $("a:contains('text')").html('new-text<span class="someclass">some other text</span>')
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜