title: jQuery file upload preview/remove image not working for new inputs
body: <p>You can find the code at <a href="https://jsfiddle.net/hxwmL1px/6/" rel="nofollow noreferrer">jsfiddle</a></p>
  
  <p>Image preview and remove function was working early (<a href="https://jsfiddle.net/hxwmL1px/4/" rel="nofollow noreferrer">jsfiddle</a>), now I used "+" button to add more inputs. But now image preview is not working also remove div is not working for new inputs. Please check the working code and help me to solve it.</p>
  
  <p>html</p>
  
  <pre><code>&lt;form&gt;
    &lt;div class="form-group portfolioimgdiv width100"&gt;
      &lt;h5 class="control-label bold"&gt;Portfolio Images&lt;/h5&gt;
      &lt;div class="socialmediaside2"&gt;
        &lt;input type="text" class="form-control" name="portfolioimgtitle[]" maxlength="10" placeholder="Image Title" /&gt;
        &lt;div class="form-group hirehide is-empty is-fileinput width100 martop10"&gt;
          &lt;input class="fileUpload" accept="image/jpeg, image/jpg" name="profilepic[]" type="file" value="Choose a file"&gt;
          &lt;div class="input-group"&gt;
            &lt;input class="form-control" required id="uploadre" placeholder="Portfolio Image" readonly&gt;&lt;span class="input-group-btn input-group-sm"&gt;&lt;button class="btn btn-fab btn-fab-mini"type="button"&gt;&lt;i class="material-icons"&gt;attach_file&lt;/i&gt;&lt;/button&gt;&lt;/span&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="removebtnimg"&gt;
        &lt;button type="button" class="btn btn-default btn-sm bckbtn addmore_img"&gt;Add&lt;span class="glyphicon glyphicon-plus"&gt;&lt;/span&gt;&lt;/button&gt;
      &lt;/div&gt;
      &lt;div class="upload-demo col-lg-12"&gt;
        &lt;img alt="your image" class="portimg" src="#"&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Jquery</p>
  
  <pre><code>$('.portfolioimgdiv').on('click', '.remove_field', function() {
    $(this).parent().parent().remove();
  });
  $('.addmore_img').click(function() {
    $('.portfolioimgdiv:last').after('&lt;div class="form-group portfolioimgdivnext width100"&gt;&lt;div class="socialmediaside2"&gt;&lt;input type="text" class="form-control" name="portfolioimgtitle[]" maxlength="10" placeholder="Image Title" /&gt;&lt;div class="form-group hirehide is-empty is-fileinput width100 martop10"&gt;&lt;input class="fileUpload" accept="image/jpeg, image/jpg" name="profilepic[]" type="file" value="Choose a file"&gt;&lt;div class="input-group"&gt;&lt;input class="form-control" required id="uploadre" placeholder="Portfolio Image" readonly&gt;&lt;span class="input-group-btn input-group-sm"&gt;&lt;button class="btn btn-fab btn-fab-mini"type="button"&gt;&lt;i class="material-icons"&gt;attach_file&lt;/i&gt;&lt;/button&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="removebtnimg"&gt;&lt;button type="button" class="btn btn-warning btn-sm remove_field"&gt;&lt;span class="glyphicon glyphicon-trash"&gt;Remove&lt;/span&gt;&lt;/button&gt;&lt;/div&gt;&lt;div class="upload-demo col-lg-12"&gt;&lt;img alt="your image" class="portimg" src="#"&gt;&lt;/div&gt;&lt;/div&gt;');
  });
  
  function readURL() {
    var $input = $(this);
    var $newinput = $(this).parent().parent().parent().find('.portimg ');
    if (this.files &amp;&amp; this.files[0]) {
      var reader = new FileReader();
      reader.onload = function(e) {
        reset($newinput.next('.delbtnmrg26'), true);
        $newinput.attr('src', e.target.result).show();
        $newinput.after('&lt;button type="button" class="delbtnmrg26 removebtn" value="remove"&gt;&lt;i class="fa fa-times" aria-hidden="true"&gt;Remove&lt;/i&gt;&lt;/button&gt;');
      }
      reader.readAsDataURL(this.files[0]);
    }
  }
  $(".fileUpload").change(readURL);
  $("form").on('click', '.delbtnmrg26', function(e) {
    reset($(this));
  });
  
  function reset(elm, prserveFileName) {
    if (elm &amp;&amp; elm.length &gt; 0) {
      var $input = elm;
      $input.prev('.portimg').attr('src', '').hide();
      if (!prserveFileName) {
        $($input).parent().parent().find('input.fileUpload').val("");
        $($input).parent().parent().find('.input-group').find('input#uploadre').val("");
      }
      elm.remove();
    }
  }
  </code></pre>