title: How to append dynamically created div into current mainDiv not all the mainDiv when click on a button
body: <p>I'm trying to appendTo a <code>&lt;div&gt;</code> into current <code>&lt;div class='mainDiv'&gt;</code> when click on a button. Now its appendTo all the <code>class='mainDiv'</code> &amp; after the cloning. I need it only to the current clicked <code>&lt;div&gt;</code>. Can someone help me to solve it?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>(function($) {
  
    function div2() {
      $('&lt;div/&gt;').addClass('div2').text('This is a Content').appendTo('.mainDiv');
    }
  
    function cloneIt() {
      $('.mainDiv').clone().detach().appendTo('body');
    }
  
    $(document).on('click', '.div1', function() {
      div2();
    });
  
    $(document).on('click', 'span', function() {
      cloneIt();
    });
  
  
  
  })(jQuery);</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>body {
    display: flex;
    justify-content: space-around;
  }
  
  .mainDiv {
    background-color: #000;
    width: 100px;
    height: 100px;
    color: #fff;
    padding: 20px;
    margin-left: 15px;
    margin-right: 15px;
  }
  
  .div1 {
    background-color: blue;
    padding: 10px;
    cursor: pointer;
  }
  
  .div2 {
    background-color: red;
    padding: 10px;
  }
  
  span {
    display: block;
    padding: 10px;
    background-color: green;
    margin-bottom: 15px;
    cursor: pointer;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="mainDiv"&gt;
    &lt;span&gt;Clone it&lt;/span&gt;
    &lt;div class="div1"&gt;click to append div&lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>