Does jQuery do any kind of caching of “selectors”?

后端 未结 14 2201
挽巷
挽巷 2020-11-27 18:14

For example, will the first piece of code perform a full search twice, or is it smart enough to cache results if no DOM changes have occurred?

if ($(\"#navba         


        
14条回答
  •  日久生厌
    2020-11-27 18:40

    There is a nice plugin out there called jQache that does exactly that. After installing the plugin, I usually do this:

    var $$ = $.q;

    And then just

    $$("#navbar .heading").hide();

    The best part of all this is that you can also flush your cache when needed if you're doing dynamic stuff, for example:

    $$("#navbar .heading", true).hide(); // flushes the cache and hides the new ( freshly found ) #navbar .heading

    And

    $$.clear(); // Clears the cache completely

提交回复
热议问题