Home › Forums › JavaScript › [Solved] Best way to reference object variable? › Reply To: Best way to reference object variable?
September 17, 2013 at 8:48 am
#150313
whatsoever
Participant
You are correct, the second example does that. You only need to reference the jQuery object once per variable. It is common practice to name jQuery referenced variables with ‘$’ in front of them, just to remind you that they inherit from the jQuery object and you can use methods like .each, .after.. etc. on them. This also would prevent you from doing something like
div = $('div.someClass');
// 200 lines of code
$(div). some jQuery method