Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript [Solved] Best way to reference object variable? Reply To: Best way to reference object variable?

#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