HTMLCollections and chaining
Quick question on the internals of jQuery and how it works with HTMLCollection objects and chaining.
If I write...
- $('div').bind('click', function(i){...}).bind('focus', function(.){...}).yada(function(){...});
...the HTMLCollection of divs is walked through for each method right?
As interacting with HTMLCollections is costly, would there be an appreciable speed gain to practise a pattern such as the following whenever working with HTMLCollections?
- var $divs = $('div'), i = 0, singleDiv;
-
- for (;singleDiv = $divs[i++];) {
- $(singleDiv).bind('click', function(i){...}).bind('focus', function(.){...}).yada(function(){...});
- }
So that way you're grabbing the HTMLElement out of the HTMLCollection just the once and interacting with that many times instead.
I know I could use .each() but it has its detractors due to speed issues.
Thoughts?