📜 ⬆️ ⬇️

jQuery - reuse selectors (offer to discuss)

When you use the same selector a lot, every time you search the DOM tree, or is there some kind of internal caching mechanism?

What is more effective (and 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 you need to think about it? If there is no such “caching” in jQuery (I don’t know how appropriate this definition is here), is it possible to implement it and how?

I propose to discuss the findings post in the article.

Source: https://habr.com/ru/post/43443/


All Articles