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

  • Home
  • SEARCH
  • 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 8725589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:04:21+00:00 2026-06-13T08:04:21+00:00

When using the _trigger method in order to fire events I’ve hit a snag

  • 0

When using the _trigger method in order to fire events I’ve hit a snag which I keep hitting but fail to properly grasp.

Basically, if there’s more then one instance of my widget, the last widget to be instantiated on the same page takes precedence over all others.

I’ve learnt and successfully used $.extend to create an object unique to the instance but I’m stumped on how to approach the following problem:

How to I properly use the _trigger method so it’s enable on a per instance basis.

(function($) {
  $.widget("a07.BearCal", {
    options: {  },
    _create: function() {
        _this = this;
        this.element.click(function() {
            _this._trigger("testTrig");
        });
    },
  });
})(jQuery);

// Instantiate widget on .full
$('.full').BearCal({
    testTrig: function() {
        console.log("testTrig event: full");
    }
});

// Instantiate widget on .mini
$('.mini').BearCal({
    testTrig: function() {
        console.log("testTrig event: mini");
    }
});

Sample here: http://jsfiddle.net/NrKVP/13/

  • 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-13T08:04:22+00:00Added an answer on June 13, 2026 at 8:04 am

    You have an accidental global variable:

    _this = this;
    

    That means that both instances of the plugin put their this into the same (global) _this in the constructor. The result is that all the plugin instances use the this for the last one bound. You want this:

    var _this = this;
    

    Demo: http://jsfiddle.net/ambiguous/9NQNz/

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

Sidebar

Related Questions

I am using an UIBarButtonItem in order to trigger events. I use the integrated
I have a custom event that I want to fire using jQuery's trigger method:
I have an Update method in my repository which I'm using to update articles
Is there a potential pitfall in using jquery on/off method and trigger to execute
I am using UpdatePanel to trigger a button click event, which saves some 100+
I am using following PHP code for trigger creation but always get error, please
I have a MySQL database holding hierarchical data using the Closure Table method. A
I am trying to access a method in my code behind called Button1_Click using
In order to load a jQuery mobile page using an anchor tag, one just
I'm using some Carbon code in my Cocoa project for handling global key events

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.