Reputation: 1083
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>
So I need to add that span tag inside the
Any ideas?
Upvotes: 1
Views: 11842
Reputation: 45922
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>')
});
Upvotes: 2
Reputation: 546045
$("a:contains('text')")
.text('new-text')
.append($('<span></span>')
.addClass('someclass')
.text('some other text')
)
;
Upvotes: 8