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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:11:40+00:00 2026-05-28T07:11:40+00:00

In jQuery plugins, which way do you think it’s best to allow a function

  • 0

In jQuery plugins, which way do you think it’s best to allow a function to be hooked in your plugin – trough triggers, or options (arguments) passed in the plugin function?

$.trigger('myplugin_completed', someData);

$(document).bind('myplugin_completed', function(event, someData){ ... });

vs

myPluginOptions.onComplete(someData);

$('.stuff').myPlugin({onComplete: function(someData){ ... }});

  • 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-28T07:11:40+00:00Added an answer on May 28, 2026 at 7:11 am

    Solution

    I think the best solution – at least in the case you described (maybe not in all the possible cases) – is to combine both in the following way:

    $('.stuff').myPlugin(/* some options here */);
    $('.stuff').trigger('myplugin.completed', someData);
    

    and this line:

    $('.stuff').on('myplugin.completed', function(event, someData){
        /* callback code */
    });
    

    is responsible for binding the event handler. It can be called also when someone passes onComplete callback within options when initializing your plugin (of course selector should be adjusted to meet the one used by the code initializing your pugin).

    Summary

    To sum up, you could:

    • create your own event (completed),
    • use your plugin’s namespace for this event / plugin (in this case myplugin),
    • use .on() function (available and preferred since jQuery 1.7),
    • if onComplete option is passed to your plugin, there is no problem in binding it within the code initializing the plugin (so from within the plugin, using the .on() function, binding event handler to your event name within your even namespace).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In jQuery, is there a function/plugin which I can use to match a given
I'm using jtemplates (jquery plugin) as my templating solution which rocks by the way!
Is it appropriate to create jQuery plugins which are specific to a single page?
I found this jquery plugin which does exactly what I need, but I want
I have a custom jQuery plugin which binds a change event to a form
I am looking for a jQuery plugin which can serve me the floating share
I know they're using a jQuery plugin, but I can't seem to find which
I'm using jQuery autocomplete plugin from jQuery website calling the controller url which return
I'm using the jQuery autocomplete plugin to get a list of locations, which works
I'm working with the jQuery Validation plugin and I wrote the following code which

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.