Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6837579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:29:39+00:00 2026-05-26T23:29:39+00:00

Is it possible to define multiple variables with a single jQuery chain? var sectionTable

  • 0

Is it possible to define multiple variables with a single jQuery chain?

var sectionTable = jQuery("#sectionsTable");
var sectionTableRows = sectionTable.find("tr");
var sectionTableColumns = sectionTableRows.find("td");

I don’t know what the syntax would be if it is possible but if you took the 3 variables above how could you chain them and would it be considered good practice?

Many thanks

Chris

EDIT: Wow, thanks for all the comments. Sorry for being vague, what I was after was a better way (if one exists) of defining child variables from a parent variable. That’s why I thought of using the chain and wondered if a way existed. Thanks for the great advice.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:29:40+00:00Added an answer on May 26, 2026 at 11:29 pm

    If you really want to, anything is possible :

    Of the top of my head, you could try to do something like this :

    var sectionTable,
        sectionTableRows, 
        sectionTableColumns = $('td', (sectionTableRows = $('tr',(sectionTable = $('#sectionsTable')))));
    

    Another ideea would be to build a mini-plugin that assigns the current jquery object to a certain field of an object :

    jQuery.fn.assignTo = function(variableName,namespace){
        var ns = namespace || window;
        ns[variableName] = this;
        return this;
    }
    

    With this peace of code you could 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 (will be attached to the window object);

    Any way, I do not encourage you to use these examples, because it doesn’t make very much sense to worsen your code’s readability in favour of fewer equal signs and var declarations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to define two variables in a vb2005 For loop in a
Does anyone know its its possible to define a table once in a .feature
Does anyone know if it possible to define the equivalent of a java custom
is it possible to define multiple output operators for an enum? I want to
Is it possible using JPA to define multiple unique constraints. @Entity class Foo {
Is it not possible to define multiple constructors in Python, with different signatures? If
Is it possible in MySQL to update a single field and select multiple different
Is it possible to define a function argument as multiple possible types? For example,
Is it possible to define multiple templates for a Repeater's ItemTemplate and switch between
I have an Exchange account with multiple calendars defined. Is it possible to query

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.