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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:10:43+00:00 2026-05-15T19:10:43+00:00

If I create a JQuery widget (code example below), and then define a public

  • 0

If I create a JQuery widget (code example below), and then define a “public” method, is there any other way to call the method other than using the following form?

$("#list").list("publicMethod"); 

I would like to create a series of widgets that all define the same methods (basically implementing the same interface), and be able to call the method without knowing anything about which widget I currently am invoking the method on. In the current form, I need to know that I am executing the method on the “list” widget.


Below is an example of creating a widget with the “public” method.

 (function($) {
    var items = [];
    var itemFocusIdx = 0;

    $.widget("ui.list", {
        // Standard stuff
        options : { ... },
        _create : function() { ... },
        destroy : function() { ... },

        // My Public Methods
        publicMethod : function() { ... }
        ...
    });
}(jQuery));
  • 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-15T19:10:44+00:00Added an answer on May 15, 2026 at 7:10 pm

    jQuery UI widgets use jQuery’s $.data(…) method to indirectly associate the widget class with the DOM element. The preferred way to call a method on the widget is exactly what was described by Max…

    $('#list').list('publicMethod');
    

    …but if you want to field a return value, you’ll have better luck calling it this way, via the data method:

    $('#list').data('list').publicMethod();
    

    However, using the second way side-steps the whole jQuery UI widget pattern, and should probably be avoided if possible.

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

Sidebar

Related Questions

I am using the code below to create a jQuery UI Dialog widget dynamically:
I'm a jQuery newb and I've been trying to create a custom slideshow widget
This is jQuery UI code example: <script type=text/javascript> //function to execute when doc ready
I am trying to create a combobox style widget (jquery-ui compatible) andcurrently I am
I'm trying to follow along the demo source code for the Draggable jQuery method,
I have two JQuery widgets, one is a sort of 'main' widget, the other
I need to customize jquery ui widget. I wanted to change only the create
Some jquery plugin extend widget use _create method, while others use _init method, can
Currently I'm using Netbeans to create a webpage. The code is listed below, and
I have created custom jQuery UI widget called uiPopover, very similar to UI-dialog (in

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.