jQuery Wrap innerHTML
i have html like this
<a href="#">like 开发者_运维技巧me on facebook</a>
and i want to wrap the text facebook so the result will be like this
<a href="#">like me on <span class="facebook-text">facebook</span></a>
how to do that in jQuery?
var html = $('a').html();
$('a').html(html.replace(/facebook/, '<span class="facebook-text">facebook</span>'));
and if you want to replace all occurrences of facebook within the string:
var html = $('a').html();
$('a').html(html.replace(/facebook/gi, '<span class="facebook-text">facebook</span>'));
Maybe you could use the $(...).contents() function to access the child nodes of your anchor tag.
http://api.jquery.com/contents/
精彩评论