How to wrap text with A element
I have html code
<td id="MyNode">开发者_Python百科;TextNode</td>
and would like to make it as
<td id="MyNode"><a href="http://www.domain.com">TextNode</a></td>
I have tried to use code below but what it does is add href attribute to TD element but I need to wrap text with A element.
$('#MyNode').add('a').attr('href', 'http://www.domain.com/');
You can use .wrapInner()
:
$('#MyNode').wrapInner('<a href="http://www.domain.com/"/>');
精彩评论