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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:44:32+00:00 2026-05-27T01:44:32+00:00

This seems something I shouldnt have to waste a question on, but I can’t

  • 0

This seems something I shouldnt have to waste a question on, but I can’t get it to work!

I’m trying to make a pretty checkbox using a <span> with a background icon and a hidden checkbox.

My HTML is

<span class="checkedBox" id="mailing_Check"></span>
<input type="checkbox" id="mailing" /> <!--(currently not hidden for testing)-->

CSS is simple:

.checkedBox { background: url('../images/iconLine.png'); background-position: -550px, 0px; display: inline-block; width: 25px; height: 25px }
.unCheckedBox { background: url('../images/iconLine.png'); background-position: -575px, 0px; display: inline-block; width: 25px; height: 25px }

I need to bind an onClick handler to the checkedBox item, toggle/flip the class to unCheckedBox and set the checkbox to checked.

Now, I have various long winded ways of doing this, but am trying to do it using jQuery toggle, or toggleClass and I can’t get it to work properly.

Just working with flipping the CSS class for now…

$('.checkedBox, unCheckedBox').live('click', function () {
    $(this).toggleClass('checkedBox').toggleClass('checkedBox');
});

That will flip it once, but is not binding properly, when I click the second time, it has no effect.

I’ve tried using this example; jQuery toggle class

But that doesn’t seem to want to work, also various other Googled results, but for some reason I am struggling.

I want to keep the code to a minimum using the minimum requirement of variables, like I say, I have some long winded method using if/else logic, but I figured jQuery should make it easier! 🙂

  • 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-27T01:44:32+00:00Added an answer on May 27, 2026 at 1:44 am

    Since you’re modifying the exact same CSS style properties on your two CSS rules (.checkedBox and .unCheckedBox), I imagine that you don’t have to toggle the .checkedbox class, because the other just overrides it.

    Even better, you can just have a class that marks all your “pretty” checkboxes, and then another that modifies the style from the default.

    Maybe something like:

    CSS

    .pretty-checkbox { /* default style rules */ }
    .pretty-checkbox.checked { /* style rules when checked */ }
    

    Then you can just worry about toggling the .checked class.

    $('.pretty-checkbox').live('click', function (e) {
        $(this).toggleClass('checked');
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This seems like I'm missing something obvious but I can't get redirects (>) to
This seems to be something obvious but I simply can't find info by googling.
This seems like something that could be quite useful and yet and I can't
This seems like it should be something very easy to do, but every time
This seems very basic and I must be missing something, but here goes anyways...
Hi this seems like it should work, from something in collectionofsomestuff select new SelectListItem(){Text
Maybe I'm missing something obvious, or maybe something sinister is happening, but this seems
This seems like it should be something I already know. We need to run
this seems straightforward enough, I don't know if it's a bug, or just something
It seems to be possible in Java to write something like this: private enum

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.