Hi there! I've been dealing with some performance clean-up of a code of a web- app that I wrote and I was wondering if jQuery does caching of the DOM references. Lets say I have a function:
function myFunction(){ $('#foo').attr("bar"); } I frequently refer to the function, so is it the case that each time I launch it, the DOM is scanned for element with "foo" id? Or maybe this reference is somehow cached? If its not, then maybe doing something like this would speed up the code execution: function DomLinker(){ this.foo = $('#foo').attr("bar"); function myFunction(){ domMember.foo.attr("bar"); } $(document).ready( domMember = new DomLinker(); } Please keep in mind that we talk about case of many executions of myFunction Please share your thoughts on this one. Best regards