2

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?

Community
  • 1
  • 1
Gaurav
  • 8,367
  • 14
  • 55
  • 90

5 Answers5

5

Use this:

   $('#test button').replaceWith('<span>new</span>')
Somnath Muluk
  • 55,015
  • 38
  • 216
  • 226
slash197
  • 9,028
  • 6
  • 41
  • 70
2

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

Lhassan Baazzi
  • 1,128
  • 1
  • 11
  • 21
1

you can usereplaceWith() method:

$('#test button').replaceWith('<p>another element</p>')
Ram
  • 143,282
  • 16
  • 168
  • 197
1

You can use the .replaceWith() method to accomplish this. For more.

Darshana
  • 2,462
  • 6
  • 28
  • 54
Michi Werner
  • 316
  • 3
  • 6
0

Solution

$('#test').find('button').replaceWith('<input type="text"/>');
 alert($('#test').html());
Talha
  • 18,898
  • 8
  • 49
  • 66