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>')
});
精彩评论