JQuery - 将div添加到父div

Pho*_*rce 2 html jquery

我有以下内容:

<div id="parentCalculation">
<div class="btn-group" role="group">
    <button type="button" id="calculate" class="btn btn-default">Add</button>
</div>

Calculate below. Click on "Add to make another calculation

<div id="CalculateDiv">
<div class="calculation form-group well well-lg col-md-4">
  <label for="cost">Enter Amount</label>
  <input type="text" id="amount" class="form-control" placeholder="0.00">
  <label for="type">Type</label>
  <input type="text" id="type" class="form-control" placeholder="e.g. transfers">
  <label for="comments">Comments</label>
  <textarea class="form-control" id="cost-comments" placeholder="Enter comments"></textarea>
</div>

</div>
</div>
Run Code Online (Sandbox Code Playgroud)

我想要做的是附加父div CalculateDiv,calculation以便有重复的值.

我使用以下JQuery:

$(document).ready(function()
                  {

                    $("#calculate").click(function()
                    {
                        var x = $('.CalculateDiv');
                        alert(x);
                        $("#parentCalculation").append(x); 


                    });

                  });
Run Code Online (Sandbox Code Playgroud)

问题是它没有添加到父div,我似乎无法弄清楚为什么.

见例子:这里

dev*_*qon 5

你的选择器搜索一个,而你有一个带有id的html:

$('.CalculateDiv'); 应该 $('#CalculateDiv');