Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As redsquare already mentioned, the selection algorithm changed in later jQuery versions (partly due to getElementsByClassName support). Additionally, I tested this with the most recent jQuery version to date (v1.6) and also added a test for document.getElementsByClassName for comparison (works at least in Firefox 4 and Chrome).</p> <p>The results in Firefox 4 were:</p> <pre><code>// With 100 non-form elements: $('.myForm') : 366ms $('form.myForm') : 766ms document.getElementsByClassName('myForm') : 11ms // Without any other elements: $('.myForm') : 365ms $('form.myForm') : 583ms document.getElementsByClassName('myForm') : 11ms </code></pre> <p>The accepted answer is outdated (and is still found by searching for something like "efficient way to find elements in jquery") and can mislead people, so I felt that I have to write this.</p> <p>Also, take a look at the time difference between jQuery and native browser selector functions. In jQuery 1.2.6 <code>$('.myForm')</code> was more than <strong>300</strong> times slower than <code>getElementsByClassName</code>, while in jQuery 1.6 it was <em>only</em> about <strong>20</strong> times slower, but still faster than <code>$('form.myForm')</code> (contrary to the outdated answer).</p> <p><strong>Note:</strong> The results were obtained with Firefox 4 (similar results with Chrome). In Opera 10 querying with tag name is only slightly faster, but Opera also supports the much faster native <code>getElementsByClassName</code>.</p> <p><strong>Test code:</strong> <a href="http://jsbin.com/ijeku5" rel="noreferrer">http://jsbin.com/ijeku5</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload