简体   繁体   English

如何在附加div内附加div?

[英]how to append div inside appended div?

I am trying to append an exiting div to another div that gets appended in the page. 我正在尝试将退出的div附加到页面中附加的另一个div。

So far I've done this, but it misses the timing or perhaps the logic is not right. 到目前为止,我已经做到了,但是它错过了时间安排,或者逻辑不正确。

$(".signature-container").append( $('#signature-pad'));  

Here is the html that i am using on a regular WordPress page : 这是我在常规WordPress页面上使用的html:

<div id="signature-pad" class="signature-pad">
<div class="signature-pad--body">
  <canvas width="664" height="235" style="touch-action: none;"></canvas>
</div>
<div class="signature-pad--footer">
  <div class="description">Sign above</div>

  <div class="signature-pad--actions">
    <div>
      <button type="button" class="button clear" data-action="clear">Clear</button>
      <button type="button" class="button" data-action="change-color">Change color</button>
      <button type="button" class="button" data-action="undo">Undo</button>

    </div>
    <div>
      <button type="button" class="button save" data-action="save-png">Save as PNG</button>
      <button type="button" class="button save" data-action="save-jpg">Save as JPG</button>
      <button type="button" class="button save" data-action="save-svg">Save as SVG</button>
    </div>
  </div>
</div>

the signature container is a ninja form that gets appended to that page. 签名容器是一种忍者形式,会附加到该页面上。

$(".signature-container").append($('#signature-pad').html());  

Here you go with a solution 在这里你有一个解决方案

$(".signature-container").append($('#signature-pad').clone());

.clone() method will clone the #signature-pad container along with it's content. .clone()方法将克隆#signature-pad容器及其内容。

Here you go with example solution https://jsfiddle.net/r736a1gn/ 在这里,您将获得示例解决方案https://jsfiddle.net/r736a1gn/

 $(".signature-container").append($('#signature-pad').clone()); 
 #signature-pad { border: 1px solid #000; } .signature-container { padding: 10px; border: 1px solid #00f; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="signature-pad"> Test 1 </div> <br/> <div class="signature-container"></div> 

Hope this will help you. 希望这会帮助你。

My believe 我相信

Problem / issue https://jsfiddle.net/u2qyseo0/ When you are trying to clone & append the HTML , your cloning is happening as #signature-pad is present, but it's not appending as .signature-container ninja form is not rendered into the DOM . 问题/问题https://jsfiddle.net/u2qyseo0/当您尝试克隆和附加HTML ,由于#signature-pad存在,您的克隆正在发生,但由于未呈现.signature-container忍者形式,因此未进行.signature-container进入DOM

Solution https://jsfiddle.net/u2qyseo0/1/ Let the .signature-container ninja form to render & then append the HTML content to it. 解决方案https://jsfiddle.net/u2qyseo0/1/.signature-container ninja表单呈现并向其附加HTML内容。

尝试这种方式:

$(document).find(".signature-container").append( $('#signature-pad').clone());  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM