Javascript 删除jquery中的div子级

Javascript 删除jquery中的div子级,javascript,jquery,Javascript,Jquery,可能重复: 我的问题是,我们如何删除按钮元素并在jquery的相同位置插入其他元素?您可以使用replaceWith()方法: $('#test button').replaceWith('<p>another element</p>') $(“#测试按钮”)。替换为(“另一个元素”) 使用以下方法: $('#test button').replaceWith('<span>new</span>') $('#测试按钮')。替换为(

可能重复:



我的问题是,我们如何删除
按钮
元素并在jquery的相同位置插入其他元素?

您可以使用
replaceWith()
方法:

$('#test button').replaceWith('<p>another element</p>')
$(“#测试按钮”)。替换为(“另一个元素

”)
使用以下方法:

   $('#test button').replaceWith('<span>new</span>')
$('#测试按钮')。替换为('new')

您可以使用
.replaceWith()
方法来完成此操作。对于.

$(“#测试按钮:第一个”)。替换为('new')
解决方案

$('#test').find('button').replaceWith('<input type="text"/>');
 alert($('#test').html());
$('test')。查找('button')。替换为('');
警报($('#test').html());

这将替换页面选择器上的所有
按钮
当然可以更改。请添加更多文本或详细信息
$('#test').find('button').replaceWith('<input type="text"/>');
 alert($('#test').html());