soooo soooo - 1 year ago 104
Javascript Question

About jquery selector

What is the best utilization for multiple jquery selector ?

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


var _this = jQuery(this)


Answer Source

The main diff between



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.