Write Effective jQuery Code

You have to keep some points in mind while writing jQuery code: 
 
1.Keep DOM insertion as min as possible.For e.g 
Instead of inserting multiple <li> elements in DOM, wrap it in <ul> and then make insertion to DOM. 
 
// wrong approach 
for(var i=0;i<=500;i  ) 
{ 
strHtml ="<li>i</li>"; 
} 
$("ul").html(strHtml); 
 
 // right approach 
strHtml="<ul>"; 
for(var i=0;i<=500;i  ) 
{ 
strHtml ="<li>i</li>"; 
} 
strHtml="</ul>"; 
$("div").html(strHtml); 
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments