title: jQuery refresh DOM after adding elements to HTML
body: <p>I did find many similar questions but none with the solution that could help me solve my problem.</p>
  
  <p>I am inserting HTML elements to my page and later on I want to count them. since the newly created elements are not part of DOM so count returns <code>0</code>. </p>
  
  <p>Code:</p>
  
  <pre><code>$('#addSlide').on('click', function(){
      var reader = new FileReader();
      reader.readAsDataURL(inputFile);
      reader.onloadend = function(){
         slideImg = URL.createObjectURL(inputFile);
         // ADDING ELEMENTS
         var slide = '&lt;div class="slide"&gt;&lt;img src="'+slideImg +'" /&gt;&lt;/div&gt;';
         $('#Container').append(slide);
      };
      // EXECUTING SOME FUNCTION
      somename();
  });
  
  function somename(){
      var slideCount = '';
      slideCount = $('#Container div').length;
      console.log(slideCount);
      // ALWAYS RETURNS '0' REGARDLESS TO HOW MANY SLIDES ARE ADDED
      if( slideCount &gt; 1 ) {
         // SOME CODE ...
      }
  }
  </code></pre>
  
  <p>How can I refresh the DOM so that I can use the newly created elements in my code?</p>