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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:10:25+00:00 2026-05-25T10:10:25+00:00

So i assume this should be pretty simple… its just a custom Checkbox plugin

  • 0

So i assume this should be pretty simple… its just a custom Checkbox plugin that takes div’s and turns them into checkboxes using css. All i really need it to do is basically swap css and trigger events. I only see need for these actions (init, check, uncheck, toggle, disable).
Any way heres what i have so far, but im stuck on the toggle method and the last part in general…

(function ($) {
    var method = {
        init: function () {
            $(this).addClass('cb-unchecked');
            $(this).click(//Should call toggle method, but unsure syntax);
        },

        check: function () {
            return this.each(function () {
                $(this).removeClass('cb-disabled cb-unchecked').addClass('cb-checked').trigger('checked', this);
            });
        },

        uncheck: function () {
            return this.each(function () {
                $(this).removeClass('cb-disabled cb-checked').addClass('cb-checked').trigger('unchecked', this);
            });
        },

        toggle: function () {
            return this.each(function () {
                var t = $(this);
                if (t.hasClass('cb-checked')) { //Should call the check function, but i dont know how...  }
                else if (t.hasClass('cb-unchecked')) { //Should call the uncheck function, but i dont know how...}
            });
        },

        disable: function () {
            return this.each(function () {
                $(this).removeClass('cb-checked cb-unchecked').addClass('cb-disabled').trigger('disabled', this);
            });
        }

    };
    $.fn.customCheckbox = function (action) {

        //Im slightly lost at what would go here
        //if(method[action]){ method[action].apply(this, arguments);  }//????

        return this;
    }
})(jQuery);

Am i headed in the right direction or should i be going about this completely differently?

  • 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-25T10:10:26+00:00Added an answer on May 25, 2026 at 10:10 am

    Yes, you are on the right track. You wrapped it in (function($){..})(jQuery) to let jQuery play nicely with other javascript libraries. You maintain chainability by return this;. You properly extend jQuery by using $.fn.customCheckbox = .... You can do as your comment says by applying the parameters to the function. Finally, just call it.

    $("input[type='checkbox']").customCheckbox('init');
    

    although i would probably move the init code into the body of $.fn.customCheckbox = function (action) {...} when !action

    $.fn.customCheckbox = function (action) {
            if(!action){
                // init here
            }
            // other logic here
            return this;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I assume this should be pretty simple, but could not get it :(. In
I assume this should be fine bool prefMatch = false; // Is the frequency
I'm using OpenLayers to display OpenStreetMap maps. (Though, I'd assume this should be general
I assume this is pretty easy so here goes; I'm trying to execute these
Here's a pretty simple idea, in this pastebin I've posted some pair of numbers.
I'm pretty sure that this is the right site for this question, but feel
I think this should be a pretty easy question to answer but I can't
This is such a basic issue that I can only assume I'm looking at
assume this following function: int binaryTree::findHeight(node *n) { if (n == NULL) { return
I assume this is really easy, and I'm missing something obvious. I'm connecting to

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.