Yes it is. Since $(this)
essentially is a pretty expensive function call triggering a Dom-Search you repeat it everytime you call $(this)
while with var elem = $(this);
you have the function-call once and store the result in a variable.
Actually it's much more expensive when passing selectors to the function than passing an DOM-Element like this
. So caching this
will have a very tiny effect only, while caching something like $("#foo[name|='bar']")
will really matter.
I prefer prepending the $
to the variable name so that it's obvious that you have a jQery Object here.
$this = $(this);
Now $this
has no significant drawback from the point of readability while having the performance advantage. Also it can be minified by compressors to a single letter variable, while $(this)
can't.