In your example, chaining is faster.
// Example 1 $('#blah_id').niftyjQueryMethod1().niftyjQueryMethod2(); // Example 2 $('#blah_id').niftyjQueryMethod1(); $('#blah_id').niftyjQueryMethod2();
In Example 1, the call to create the jQuery object ( $('#blah_id') ) is made only once. In Example 2, this is done twice. This means that the second call will be slower.
If you do not want to put them in a chain, you can cache the selection in a variable:
var blah = $('#blah_id'); blah.niftyjQueryMethod1(); blah.niftyjQueryMethod2();
Assuming that the methods do not affect which elements are present in the selection (for example, parent , find or filter do), this will be approximately the same as Example 1.
lonesomeday
source share