
jQuery - reusing selectors (suggestion to discuss)
When using the same selector repeatedly, does the DOM tree search each time, or is there some kind of internal “caching” mechanism?
What is more effective (and by how much)?
jQuery ('# mySelector'). attr ('border', '1px');
jQuery ('# mySelector'). attr ('color', 'red');
jQuery ('# mySelector'). show ();
or
mySelector = jQuery ('# mySelector');
mySelector.attr ('border', '1px');
mySelector.attr ('color', 'red');
mySelector.show ();
Those. Do I need to think about this? If jQuery does not have such “caching” (I don’t know how relevant this definition is), is it possible to implement it and how?
I propose to discuss
What is more effective (and by how much)?
jQuery ('# mySelector'). attr ('border', '1px');
jQuery ('# mySelector'). attr ('color', 'red');
jQuery ('# mySelector'). show ();
or
mySelector = jQuery ('# mySelector');
mySelector.attr ('border', '1px');
mySelector.attr ('color', 'red');
mySelector.show ();
Those. Do I need to think about this? If jQuery does not have such “caching” (I don’t know how relevant this definition is), is it possible to implement it and how?
I propose to discuss