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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:35:05+00:00 2026-06-02T01:35:05+00:00

I have recently written my first simple jQuery plugin. Proud I am. http://jsfiddle.net/johnhoffman/wSeLY/1/ (function($)

  • 0

I have recently written my first simple jQuery plugin. Proud I am.

http://jsfiddle.net/johnhoffman/wSeLY/1/

(function($) {
    $.fn.makeRed = function() {
        return this.each(function() {
            $(this).css("color", "#f00");
        });
    }
})(jQuery);

I am wondering why it works though. I pass the jQuery object into this enclosed function that runs immediately.

Subsequently, isn’t the |$| object a local variable within that anonymous function? How does it change the global singleton jQuery object?

In other words, aren’t I just adding a function via $.fn.myFunctionName to the object |$| local to the enclosed function? How does it change the global jQuery object and make my function (makeRed) available to selectors all over the global scope of my script?

  • 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-02T01:35:07+00:00Added an answer on June 2, 2026 at 1:35 am

    isn’t the |$| object a local variable within that anonymous function?

    Yes, $ is a local variable in the function but, and this is a big but, it is a reference to the jQuery object that is globally accessible. Things look like this:

    window.jQuery (global) ----->-----> { ... }
                                        ^
                                        |
    $ (local) ------------------>-------+
    

    So, you have two variables that point at the same object and that object still exists after your anonymous function is called.

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

Sidebar

Related Questions

I have recently written an application(vb.net) that stores and allows searching for old council
I've recently been using this set up on a website... http://jsfiddle.net/mnRNE/ CSS body {
I have recently written a dynamic querying tool using expression trees and as I
I have recently inherited a J2EE Struts web app that was written back in
I have recently begun using Scala. I've written a DSL in it which can
I have recently started learning Ruby, as my first programming language. I feel comfortable
I have a website written in-house, using a 3rd party login mechanism. Recently we've
I have this app, originally written for iOS 2.x. I recently needed to add
I have recently read Apple's sample code for MVCNetworking written by Apple's Developer Technical
I have written an XMPP client with jQuery+Strophe. It all works well (1-on-1, presence,

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.