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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:54:25+00:00 2026-05-22T15:54:25+00:00

I have this javascript code that creates a slider: http://jsfiddle.net/samccone/ZMkkd/ Now, i want to

  • 0

I have this javascript code that creates a slider:

http://jsfiddle.net/samccone/ZMkkd/

Now, i want to use this code on a checkbox input. the problem is that the code creates a child element that slides in it’s parent using a css position, and an input cannot have a child.

My idea was to use background-position and just slide the background of the input from left to right using css instead of using real positioning.

How can I adapt this script? It is quite easy I think but after a couple of tries I just gave up, i’m not good enough :).

Thanks for your help,

Christopher

  • 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-22T15:54:26+00:00Added an answer on May 22, 2026 at 3:54 pm

    Believe it or not, for checkboxes a switch effect is possible to create without JavaScript.

    If you follow your checkbox with a label:

    <input type="checkbox" id="jim" />
    <label for="jim"></label>
    

    You will find that you can select the label with the next sibling selector:

    input + label { /* some CSS */ }
    

    Why is that useful? Because using the pseudo selector :checked you can now style the label based on the state of the checkbox:

    input + label { background-position: 0 0; }
    input:checked + label { background-position: 100% 0; }
    

    Clearly, due to the for=”jim” attribute, clicking on the label will change the state of the checkbox. So if you hide the checkbox, you end up with a styled, clickable label.

    input { display: none; }
    

    Of course, labels can have children so you can be as fancy as you want with your recreation of a switch. And you should be careful to include :focus styles as well, for people who tab to your checkbox rather than click on it.

    For browsers that do not support the :checked pseudo class (IE8 and below), it’s pretty easy to emulate with a global handler and a ‘checked’ class. Something like:

    jQuery(document).bind('change', function(e){
      var elem = jQuery(e.target);
    
      // If this is not a checkox, do nothing.
      if (elem.attr('type') !== 'checkbox') { return; }
    
      // Add or remove checked class based on current state.
      if (elem.attr('checked')) { elem.removeClass('checked'); }
      else { elem.addClass('checked'); }
    });
    

    …should do it.

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

Sidebar

Related Questions

I have this function in my Javascript Code that updates html fields with their
I have this java code: <script src=http://www.google.com/jsapi></script> <script type=text/javascript> google.load(jquery, 1.2.6); $(a#more).click(function() { $(#info_box).show(blind,
I have some javascript code that creates an img tag with a mouseover callback,
I usually do not have difficulty to read JavaScript code but for this one
I'm sure I'm going to have to write supporting javascript code to do this.
See here: http://code.google.com/p/ie7-js/ Does anyone have any experience or remarks about this javascript? Is
I have this Javascript data: [{id:123,type:test},{id:154,type:another}] How would you transform that into something so
I have this line of JavaScript and the behavior I am seeing is that
I have currently implemented this image slider http://www.dreamcss.com/2009/04/create-beautiful-jquery-sliders.html on a site but for some
I have this bit of javascript written with jQuery 1.2.5. It's contained inside the

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.