[英]Add div with content inside another div on button click
I have a simple dropdown and a checkbox as children of a div.我有一个简单的下拉列表和一个复选框作为 div 的子项。 I am trying to replicate this div when a user clicks on the "Add Another" button.
当用户单击“添加另一个”按钮时,我试图复制此 div。
This is my div:这是我的 div:
<div id="dominantDiv">
<div id="childDiv">
<div>
Dominant Item
@Html.CheckBox("checkbox", true, new { @onClick = "toggleSelect()" })
@Html.Hidden("hidCheck")
</div>
<div>
@Html.DropDownList("Drop", (IEnumerable
<SelectListItem>)TempData["Drop"], new { @id = "enableDrop", required = true })
@Html.Hidden("hidSelection")
<button type="button" id="addDominantBtn" onclick="addDominant()">Add Another</button>
</div>
</div>
</div>
I've already tried using appendChild我已经尝试过使用 appendChild
function addDominant() {
$("#dominantDiv").appendChild($("#childDiv"));
}
to get the whole div and re-add it to its parent but I get the error获取整个 div 并将其重新添加到其父级,但出现错误
Uncaught TypeError: $(...).appendChild is not a function
at addDominant
at HTMLButtonElement.onclick
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.