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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:30:58+00:00 2026-06-15T17:30:58+00:00

Sorry if this is a base question but I seem to have a misconception

  • 0

Sorry if this is a base question but I seem to have a misconception on how plugins in JQuery work and Google ain’t helping much.

Imagine I have:

methods = {
    init : function(opts){

        options = $.extend(options, opts);

        return this.each(function(){
            data = $(this).data('prodigal');

            if(!data){

                if(options.isActive === false){
                    $(options.tpl.overlay).css({ 'opacity': options.overlay.opacity }).appendTo('body');
                    options.isActive = true;
                }
            }
        });
    }
};

Now options.isActive is a boolean of true or false to say whether or not the options.tpl.overlay option should be added to the body of the document. It ensures my options.tpl.overlay appends only once to the document and it works, but I am unsure how it works.

When I call:

$('.view_title_images').prodigal();
$('.glglg').prodigal();

It still only adds once. I was always led to believe that the plugin is formed and the init function called for every “call” you make, i.e. $('.view_title_images,.glglg').prodigal(); would form and call the init function once.

So how exactly does the init function run in a JQuery plugin?

  • 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-15T17:30:59+00:00Added an answer on June 15, 2026 at 5:30 pm

    I am seeing this behaviour because the plugin is actually instantiated the first time it is run as a static object within the jQuery plugin framework.

    So every successive call to the init function will call this global object. Since the options object is a reference to that object in the static object changing the boolean each time is actually saved for future calls to the plugin.

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

Sidebar

Related Questions

Sorry for this foolish question, but I'm quite new to C++. I have a
Sorry this is a basic question, but all my research just barely missed answering
sorry this is such a simple question but I can't figure it out. How
Sorry for this simple question, but I can't solve it... There is an example:
Sorry if this question seems stupid, but it's stumped me for a couple days,
Sorry if this is a stupid question, but is there an easy way to
Sorry if this question is a bit open ended, but I'm pretty new to
Sorry for this question but I can't find my error! In my Project I
Just starting with php and sorry if this is a newbie question but i'm
Sorry if this is an elementary question but I've just started to consider whether

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.