<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.
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
精彩评论