tags:

views:

27

answers:

1
<div id='one' class='foo'>Hello</div>

$('#one').replaceWith("<div id='one'>World</div>")

Above code is producing

<div id='one' class='foo'>World</div>

However the desired output is

<div id='one'>World</div>

Notice that replaceWith is changing the content inside the div but not the attributes of the div itself.

+1  A: 

As with the others that have commented on this, I can not reproduce the problem.

$(document).ready(function(){

  $('div').live('click', function(){

    $('#one').replaceWith('<div id="one">World</div>');

  });

});​

That causes

<div id='one' class='foo'>Hello</div> 

this to change to:

<div id='one'>World</div>

However, alternatively you could use this:

$(document).ready(function(){

  $('div').live('click', function(){

    $('#one').removeAttr('class').html('World');

  });

});​

Mind you those are on click, you could remove the click and do it however you like.

See here: http://jsbin.com/adesi3/edit

MoDFoX
my bad. It is working as expected. Not sure what happened there.
Nadal