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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:17:31+00:00 2026-05-23T23:17:31+00:00

I thought jQuery widgets were jQuery objects that were handily linked to DOM objects

  • 0

I thought jQuery widgets were jQuery objects that were handily linked to DOM objects (so you could store state, for example, or handle events), but I’m having some problem with understanding the instance model here. I have an object as such ;

var xs_widgets = {

    jQuery : $,

    options: { },

    _create: function () {
        this.make_sortable() ;
    },

    _init: function () { alert ( 'init' ) ; }

    make_sortable: function () { alert ( 'make-sortable' ) ; }
}

I bind it to jQuery with ;

jQuery.widget( "ui.xs_widgets", xs_widgets );

And then, I try to bind some DOM elements to the widget ;

$('li.widget').xs_widgets();

Now here’s the thing. I thought that each <li class="widget"> got a jQuery object attached, but from what I can gather there’s a global xs_widget object regardless, and it gets fed the jQuery objects from the query above, and you yourself have to deal with instance data? I thought the whole point of the widgets was to avoid the overhead of dealing with instances? The above code run against HTML that contains, say, two <li> elements yields ;

make-sortable
init
make-sortable
init

I was expecting ;

make-sortable
init
init

Oh, please help! I’m reading tutorials and articles, but I seem to be missing something vital somewhere.

  • 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-23T23:17:31+00:00Added an answer on May 23, 2026 at 11:17 pm

    Your xs_widgets function widget gets called once for each matching element in your selector (so, twice with two tags).

    I thought that each got a jQuery object attached.

    They do. Which is why _create and _init are both called twice. However, the create method will only be called once when adding the widget to the element. If you call $('li.widget').xs_widgets(); again right after your first call, you’ll only get:

    init
    init

    Here’s an example.

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

Sidebar

Related Questions

I thought I heard that py2exe was able to do this, but I never
I thought jQuery Intellisense was supposed to be improved with SP1. I even downloaded
I thought I had seen a bug report about this on the jQuery site,
How do you compare a value from jQuery with a fixed number? I thought
I would like to manipulate the HTML inside an iframe using jQuery. I thought
I thought that there was some way in .net 3.0 to give an array
I thought people would be working on little code projects together, but I don't
I have a Javascript function that accepts a list of HTML nodes, but it
I thought there was only one - included in jQuery UI and documented here
I am a COMPLETE beginner at JQuery (and javascript in general) but I'm having

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.