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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:23:36+00:00 2026-05-29T05:23:36+00:00

I have some forms and I would like to add classes to the elements.

  • 0

I have some forms and I would like to add classes to the elements. Here is an example:

<form ... id="test1"> </form>
<form ... id="test2"> </form>

I found the following but I don’t understand the syntax of the first few lines

(function ($) {

    $.widget("ui.format", {

        _init: function () {

            var self = this; //the plugin object
            var o = self.options; //user options

            //get all form elements
            var form = self.element; //the form that reformed was called on
            var fieldsets = form.find('fieldset');
            var legends = form.find('legend');
            var text_inputs = form.find('input[type="text"] , input[type="password"] , textarea');
            var checkboxes = form.find('input[type="checkbox"]');
            var radios = form.find('input[type="radio"]');
            var buttons = form.find('input[type="reset"] , input[type="submit"], button');

            //add appropraite styles to form elements
            form.addClass('ui-widget');
            fieldsets.addClass('ui-widget ui-widget-content ui-corner-all');
            legends.addClass('ui-widget ui-widget-header ui-corner-all');
            text_inputs.addClass('ui-widget ui-widget-content ui-corner-all');




 }); //end plugin

})(jQuery);

In particular I don’t understand this:

(function ($) {
    $.widget("ui.format", {
        _init: function () {

and the last line:

})(jQuery);

Can someone explain to me what it means and step me through just these three lines.

For example:

  • What does the _init mean
  • Can I use mixed case for “ui.format” and is this the name of the function?
  • What’s the .widget mean, how could I apply this code to my form? I assume I would need to call it somehow from inside my document ready and then attach it to a particular form id.
  • Also what happens if I apply this to my form and then later on apply it again. Will it add the same classes twice?
  • 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-29T05:23:37+00:00Added an answer on May 29, 2026 at 5:23 am

    The (function ($) { starts off a pattern that is commonly used with jQuery plugins (and many other JavaScript functions). The entire pattern is:

    (function ($) { //declare an anonymous function that accepts a parameter called '$'
        //your code goes here
    }(jQuery)); //Close the anonymous function and pass it the jQuery object
    

    Wrapping the whole thing in parentheses makes it execute as soon as it loads (i.e., before the DOM is ready).

    The $.widget("ui.format", { begins to extend the jQuery widget factory passing in ‘ui.format’ as the “namespace.widgetname” and then the { starts the object to pass in.

    “what does the _init mean”: _init: function() { is a function called “_init” that is being defined in the object passed in to the widget factory.

    “can I use mixed case for “ui.format””: No, as it’s the namespaced widget that is being modified and JavaScript is case-sensitive.

    As far as applying this to your code, I haven’t seen this plugin before so I’ll have to refer you to the documentation on the site where you got it.

    In general, you apply jQuery widgets by passing a selector to the jQuery object and calling the widget (i.e., $('form#test1').ui.widget();).

    You can also add classes with the .addClass() function.

    $(document).ready(function () {
        $('form#test1').addClass('yourClassHere');
        $('form#test1').addClass('yourNextClassHere');
        //or just chain them together like so...
        $('form#test1').addClass('classOne').addClass('classTwo').addClass('classThree');
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a number of inputs in some forms and I would like to
I have a fairly simple Windows Forms application that I would like to add
this is some form generation code. I would like to add a captcha or
I have the following form code: # forms.py class SomeForm(forms.Form): hello = forms.CharField(max_length=40) world
So I have an Access application, and I'd like some forms to be maximised
I have a windows application with an MDI form and some child forms. I
I have a MDI container form, and some child forms that update their title
I would like to add elements to a list box on a jframe, from
I have my business classes protected by EJB3 security annotations, now I would like
I have a registration page and would like to perform some validation (in addition

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.