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 8595811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:31:42+00:00 2026-06-12T00:31:42+00:00

I am not able to understand how jQuery chaining works. jQuery(div).attr(id, _id) .hide() .show();

  • 0

I am not able to understand how jQuery chaining works.

jQuery("div").attr("id", "_id")
    .hide()
    .show();

I did something like chaining, but I’m not sure if it’s the same logic that jQuery uses.

var fun = (function (parma) {
return function () {
    return {
        start: function () {
            console.log("start");
            return this;
        },

        mid: function () {
            console.log("mid");
            return this;
        },

        last: function () {
            console.log("last");
            return this;
        }
    }
}

})();

// Working
fun().start()
    .mid()
    .last();
  • 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-06-12T00:31:43+00:00Added an answer on June 12, 2026 at 12:31 am

    If the return value of a function is an object that has a method, you can call that method immediately. Simple as that.

    Since you’re returning this, you’re returning the same object that the previous method was called on. That means you’re returning an object with all the same methods.


    Think of it this way:

    var f = {
        foo: function() {
                 console.log("foo");
                 return b;
             }
    };
    
    var b = {
        bar: function() {
                 console.log("bar");
                 return f;
             } 
    };
    

    Here we have two objects.

    • The f object has a method called foo that returns the b object.
    • The b object has a method called bar that returns the f object.

    Because of this, after calling foo, we can call bar, and vice versa.

    f.foo().bar().foo().bar(); // etc
    

    But because f doesn’t have bar and b doesn’t have foo, we can never call the same method twice.


    But what if we only had one object, that had both methods, and both methods always returned the same original object?

    var fb = {
        foo: function() {
                 console.log("foo");
                 return fb;
             },
        bar: function() {
                 console.log("bar");
                 return fb;
             }
    };
    

    Now we’re always returning an object that has both the foo and bar methods, so we can call either method.

    fb.foo().bar().bar().bar().foo().foo().bar();
    

    So now the only real difference is that we are returning fb instead of this, but it doesn’t matter since they’re the same object. The code above could do return this; and it would behave the same.

    It would matter if you wanted to create several instances of the object, but that’s a question of object orientation techniques, not method chaining.

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

Sidebar

Related Questions

I have tried a lot but not been able to understand the steps involved
Hello I am not able to understand how to use jQuery plug-ins in cakePHP.
I am not able to understand how to rotate the image. I am trying
I am not able to understand few things on the Garbage collection. Firstly, how
I'm not able to understand the difference between Thread vs ThreadPool. Consider i've to
I have a legacy script which I am not able to understand. The script
I am relatively a new Android developer and I am not able to understand
I dont understand why I am not able to update a field on the
I'm wondering if the following may be possible using something like jQuery. I've looked
I know its possible to integrate jQuery within Firefox addons, but are we able

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.