ITJ Managment ki traf se Fourm per 200 Posts Complete honay per aap ko Mubarik ho,I hope k ye Safar InshALLAH aesay hi Chalta rahay ga.

Image

4 Performance Tips for Elements Matching in jQuery

Post Reply
User avatar
Baal Veer
Super Moderator
Posts: 114
Joined: Fri Jul 06, 2018 10:29 am
Location: Punjab
Gender:
Age: 29
Pakistan

4 Performance Tips for Elements Matching in jQuery

#1

Post by Baal Veer » Fri Sep 21, 2018 3:20 pm

Always use ID to select an element if you can. This is the fastest way to select elements.
Avoid matching elements by class name. Selecting with class name only will make jQuery search every element in the entire page. If you need to match elements by classname then use the element tag combined with the class name.
Avoid this: jQuery(".ElementClass")
Do this: jQuery("div.ElementClass")
Narrow it down. For example, if you know that the elements you want to select are in the top menu of the page then specify it when selecting.
jQuery("#TopMenu").find("li.MenuItem");

Avoid selecting the same element more than once. Store your selected element or use chaining.
Avoid this:
jQuery("#MyElement").addClass("SelectedItem");

jQuery("#MyElement").show();
Do this:
jQuery("#MyElement").addClass("SelectedItem").show();

Or this:
var myElement = jQuery("#MyElement");

myElement.addClass("SelectedItem")
// some more code...
myElement.show();

Post Reply

Return to “PHP & JavaScripts”

HTML Center : Disclaimer