Jquery 如何替换div中的信息

Jquery 如何替换div中的信息,jquery,Jquery,当我使用jQuery单击一个div时,我试图用另一个div替换它,但我做不到,我不知道是否需要在一个div上使用hide属性 这是密码 <div id="prepersonal">this is a test 1</div> <div id="personal">this is a test 2</div> 有人知道答案吗?以下内容将div中的内容替换为单击编辑的内容: $(function(){ $('#prepersonal').on

当我使用jQuery单击一个div时,我试图用另一个div替换它,但我做不到,我不知道是否需要在一个div上使用hide属性

这是密码

<div id="prepersonal">this is a test 1</div>
<div id="personal">this is a test 2</div>

有人知道答案吗?

以下内容将
div
中的内容替换为
单击
编辑的内容:

$(function(){
    $('#prepersonal').on('click', function(){
        $('#personal').html(this.innerHTML);
    });
});

在您的评论之后:

$(function(){
    var a = $('#prepersonal'), b = $('#personal');

    // you can remove this call to hide by initially
    // hiding the div using display:none; in CSS
    b.hide();

    a.on('click', function(){
        toggledivs();
    });
    b.on('click', function(){
        toggledivs();
    });

    function toggledivs(){
        a.toggle();
        b.toggle();  
    };
});

你的javascript是什么?这一点不清楚,请按“删除并插入另一个div”中的方式删除。或者隐藏你的一个div?你需要替换什么?必须隐藏个人div,当你单击prepersonal时,隐藏prepersonal并显示personal
$(function(){
    var a = $('#prepersonal'), b = $('#personal');

    // you can remove this call to hide by initially
    // hiding the div using display:none; in CSS
    b.hide();

    a.on('click', function(){
        toggledivs();
    });
    b.on('click', function(){
        toggledivs();
    });

    function toggledivs(){
        a.toggle();
        b.toggle();  
    };
});
$(function() {
    $("#prepersonal").click(function(){
        $("#personal").html($("#prepersonal").html()); //You can use the text() method instead of html if you need only the text
        $("prepersonal").css("display", "none");
    });
);
$(function(){
$('#prepersonal').on('click', function(){
    $(this).replaceWith($('#personal'));
});
});