soooo soooo - 1 month ago 17
Javascript Question

About jquery selector

What is the best utilization for multiple jquery selector ?

jQuery(this) / jQuery('#id')


or

var _this = jQuery(this)


?

Answer

The main diff between

jQuery('#id');

and

var selector = jQuery('#id');

for first type, if you are calling the same thing more than one time than for each call there is DOM traverse to get the element reference, but in second case it saves the reference and do not traverse DOM for each request. This saves the overhead.