If you really want this, anything is possible:
At the top of your head, you can try to do something like this:
var sectionTable, sectionTableRows, sectionTableColumns = $('td', (sectionTableRows = $('tr',(sectionTable = $('#sectionsTable')))));
Another idea would be to create a mini plugin that assigns the current jquery object to a specific object field:
jQuery.fn.assignTo = function(variableName,namespace){ var ns = namespace || window; ns[variableName] = this; return this; }
With this calm code, you can do the following:
var sections = {}; jQuery("#sectionsTable") .assignTo('sectionTable',sections) .find("tr") .assignTo('sectionTableRows',sections) .find("td") .assignTo('sectionTableColumns',sections); console.log(sections.sectionTable); console.log(sections.sectionTableRows); console.log(sections.sectionTableColumns);
Of course, if you do not specify any namespace, the variables will be global (they will be bound to the window object);
In any case, I do not recommend you to use these examples, because it does not make much sense to impair code readability in favor of smaller equal signs and var declarations.
source share