title: What is best way to create elements and append them to the dom in jquery?
body: <p>Let's say I am adding li elements in javascript code with jQuery.</p>
  
  <p><strong>Example 1:</strong></p>
  
  <pre><code>for(var i=0 i&lt;=5; i++){
  
      var li = $("&lt;li/&gt;");
      li.html("teest "+i);
      $("#ulid").append(li);
  
  }
  </code></pre>
  
  <p>I've learned that the above example is a bad practice due to the fact that the loop rebuilds dom each time it hits append(li).</p>
  
  <p>If that is the case, what is the best way to do the exact same thing as the above example?</p>