jquery替换div内容html()

Joh*_*000 9 jquery

我只是尝试用绑定到点击事件的新内容替换div的内容.

的jsfiddle

当我使用appendTo()而不是html()它的工作,但我需要清除旧的内容,所以我有点困惑为什么这不像它应该做的那样工作

Adi*_*dil 13

您使用id selctor content代替selectorselector代替.你可以这样做content#

现场演示

function showitnow() {
    var div_data = "<div ><a href='XXX'>XXX</a></div>";
    $("#test1").html(div_data);

}

$("#button1").click(function() {
     showitnow();
});
?
Run Code Online (Sandbox Code Playgroud)