<div id='test'>
<span></span>
<p></p>
<button></button>
<h1></h1>
</div>
我的問題是,我們如何能去除button
元素,並插入一些其它的相同位置在jQuery中?
<div id='test'>
<span></span>
<p></p>
<button></button>
<h1></h1>
</div>
我的問題是,我們如何能去除button
元素,並插入一些其它的相同位置在jQuery中?
使用此:
$('#test button').replaceWith('<span>new</span>')
可以使用.replaceWith()
方法來做到這一點。對於more。
$('#test button:first').replaceWith('<span>new</span>')
解決方案
$('#test').find('button').replaceWith('<input type="text"/>');
alert($('#test').html());
請添加更多文字或細節 –