Friday, 3 January 2014

jquery patterns append

<script> /* Title: append * Description: use string concatenate and set innerHTML */ // antipattern // appending inside $.each(reallyLongArray, function (count, item) { var newLI = '<li>' + item + '</li>'; $('#ballers').append(newLI); }); // documentFragment off-DOM var frag = document.createDocumentFragment(); $.each(reallyLongArray, function (count, item) { var newLI = $('<li>' + item + '</li>'); frag.appendChild(newLI[0]); }); $('#ballers')[0].appendChild(frag); // string concatenate and set innerHTML var myhtml = ''; $.each(reallyLongArray, function (count, item) { myhtml += '<li>' + item + '</li>'; }); $('#ballers').html(myhtml); </script>
I hope you will enjoy the tips while playing with JavaScript. I would like to have feedbackfrom my blog readers. Your valuable feedback, question, or comments about this article 
are always welcome.

No comments:

Post a Comment