1

I know you can cache a selector to improve performance if your going to use it more than once by doing:

mySelector = $('#mySelectorId');

Is it possible to cache selectors that are going to be added in the future without doing the below?

var selector;

$('#something').click(function(){
    $('body').append('<div id="futureSelector"></div>');
    selector = $('#futureSelector');
})
imperium2335
  • 23,402
  • 38
  • 111
  • 190

1 Answers1

0

I think not, because jQuery method returns object. And you can't store object which doesn't exist.

Are
  • 2,160
  • 1
  • 21
  • 31