<a id="test">test</a>
比如把上面的$('#test')替换成<div>test</div>
$('#test')
<div>test</div>
使用replaceWith:
replaceWith
$('#test').replaceWith('<div>test</div>');
更新
注意,该函数返回被替换的DOM元素,如果要获得替换后的DOM元素,则需使用replaceAll
Replaces the elements matched by the specified selector with the matched elements. As of jQuery 1.3.2, returns all of the inserted elements. This function is the complement to replaceWith() which does the same task with the parameters reversed.
标签
查看
1268 次