I'm trying to get my head around jQuery caching and how it improves performance and how it should be used?
As I understand it, when you use a jQuery selector you are searching the DOM and creating a jQuery object which you can traverse. Does that mean if you create a jQuery object of the html body tag you can avoid the need to traverse the DOM when creating new jQuery objects? Would there be any point to doing that?
Considering ...
var htmlBody = $('body');
$('header',htmlBody).css('background','green');
$('footer',htmlBody).css('background','yellow');
Would the above piece of code be cheaper/use less resources by creating new objects and traversing the DOM than...
$('header').css('background','green');
$('footer').css('background','yellow');
Aucun commentaire:
Enregistrer un commentaire