2

可能重复:
将 Div 替换为另一个 Div

<div id='test'>
 <span></span>
 <p></p>
 <button></button>
 <h1></h1>
</div>

我的问题是,我们如何删除button 元素并在 jquery 的同一位置插入另一个元素?

4

5 回答 5

5

用这个:

   $('#test button').replaceWith('<span>new</span>')
于 2012-05-28T11:20:42.897 回答
2

$('#test button:first').replaceWith('<span>new</span>')

于 2012-05-28T11:25:08.003 回答
1

您可以使用该.replaceWith()方法来完成此操作。更多。_

于 2012-05-28T11:20:59.750 回答
1

你可以使用replaceWith()方法:

$('#test button').replaceWith('<p>another element</p>')
于 2012-05-28T11:20:40.523 回答
0

解决方案

$('#test').find('button').replaceWith('<input type="text"/>');
 alert($('#test').html());
于 2012-05-28T11:31:53.383 回答