0
$(function () {
    var $dom = $('#dom');
    $('#ddom').on('click', function(){
        $(this).text($dom.val());
    });
});

only get one dom once , use it everyWhere, jsfiddle link

陆同春
  • 9
  • 4
  • 3
    What do you mean by **dom** here? the document or some element? Yes caching is good if you are dealing with large size DOM _(document object model)_...! – Jai Mar 03 '16 at 11:37
  • Yes, to avoid calling `jQuery()` at each occurrence in `.ready()` handler where `#dom` element is used – guest271314 Mar 03 '16 at 11:44
  • you are right but in my question , i should have mentioned that i use the dom cashe in the callbacks , so the momery can't be recycle by js engine.if i do like this , how will it influence the performance, will memory leak?and dom in js will connect with the document all the time. – 陆同春 Mar 03 '16 at 12:27

0 Answers0