-_-#【减少 DOM 访问】缓存已经访问过的元素

Minimize DOM Access
Cache references to accessed elements

选择器查询是开销很大的方法。所以,使用选择器的次数应该越少越好,并且尽可能缓存选中的结果,便于以后反复使用。比如,下面这样的写法就是糟糕的写法:

jQuery('#top').find('p.classA');
jQuery('#top').find('p.classB');

更好的写法是:

var cached = jQuery('#top');
cached.find('p.classA'); 
cached.find('p.classB');

高性能JavaScript

原文地址:https://www.cnblogs.com/jzm17173/p/3356777.html