Possible Duplicate:
Replace Div with another Div
<div id='test'>
<span></span>
<p></p>
<button></button>
<h1></h1>
</div>
My question is , how we can remove the button
element and insert someother on the same position in jquery?
Possible Duplicate:
Replace Div with another Div
<div id='test'>
<span></span>
<p></p>
<button></button>
<h1></h1>
</div>
My question is , how we can remove the button
element and insert someother on the same position in jquery?
Use this:
$('#test button').replaceWith('<span>new</span>')
you can usereplaceWith()
method:
$('#test button').replaceWith('<p>another element</p>')
You can use the .replaceWith()
method to accomplish this. For more.
Solution
$('#test').find('button').replaceWith('<input type="text"/>');
alert($('#test').html());