4 Performance Tips for Elements Matching in jQuery

/ / JavaScript /
  • 1.6 out of 5 Stars
Please note: this article is over 13 years old. Information may be out of date.
  1. Always use ID to select an element if you can. This is the fastest way to select elements.
  2. 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:
    Do this:
  3. 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.
  4. 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...
Dissect your rivals' key traffic drivers

Rate This Article

How would you rate the quality of this content?
Currently rated: 1.6 out of 5 stars. 3 users have rated this article. Select your rating:
  • 1.6 out of 5 Stars
  • 1
  • 2
  • 3
  • 4
  • 5

Related Articles

Creative Maintenance Designs

50+ Creative Maintenance Page Designs From Real Websites

In addition to our website maintenance page tutorial, we've decided to publish our collection of the most creative and original maintenance page designs from across the web. We believe that this is the largest collection ever assembled.
IP Lookup

7 Reasons Why You Should Choose Our IP Address Lookup Tool

A few weeks ago we have published a new tool, the IP Address Lookup, which allows to get a buch of different information about an IP address including its reverse DNS hostname, geolocation, whois data (network range, network name, organization and its address and contact details), ASN details, and more.
PHP Performance

The Fastest PHP Function to Check if a Value Exists in an Array. isset vs array_search vs in_array vs other methods

In this article we will find out the fastest PHP function to check if an array contains a value. We will test and compare the performance of five different methods. We will analyze how the parameter $strict affects the performance of array_search and in_array.

Partial Page Rendering Using Hidden IFrame

Partial-page rendering removes the need for the whole web page to be refreshed as the result of a postback. Instead, only individual regions of the page that have changed are updated. As a result, users do not see the whole page reload with every postback, which makes user interaction with the Web page more seamless.

What is the AJAX enabled Google tool-kit?

First things first, Asynchronous JavaScript and XML (AJAX) is not a technology. AJAX is a technique that has brought about a great change in the world of web development. The AJAX technique comes in response to the increasing demand of interactive web applications.
Improve Your Display Campaigns & Get More ROI