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.


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
Age: 29

4 Performance Tips for Elements Matching in jQuery


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.

Avoid selecting the same element more than once. Store your selected element or use chaining.
Avoid this:

Do this:

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

// some more code...;

Post Reply

Return to “PHP & JavaScripts”

HTML Center : Disclaimer