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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:22:58+00:00 2026-05-26T06:22:58+00:00

I was looking for a script that allows me to deselect a radio button.

  • 0

I was looking for a script that allows me to deselect a radio button. I found one on SO and implemented it here…

http://jsfiddle.net/sparky672/YFsVK/1/

As you can see it’s working great but only when you click on the radio button itself. (You can also “select” a button by clicking on its corresponding <label> text. This is how the <label> operates by default.)

However, I also need to be able to “deselect” a radio button by only clicking on its corresponding <label>, and this is where I need some help.

(Why? Because I’m using a plugin that graphically alters the look of the radio button using an image sprite contained within the <label> that covers over the default radio buttons. There is a line within my jsFiddle you can activate to see the plugin in action.)

I’m sure I just need to tweak this script a bit but I cannot seem to get it correct. I believe I just need to “select” the <label> while manipulating the corresponding radio button. A <label> is “attached” to a button by placing the id of the button in the for attribute of the corresponding <label>.

JavaScript:

$(document).ready(function() {

    $('input[name="amount"]').mousedown(function(e) { // allows radio button deselection
        var $self = $(this);
        if ($self.is(':checked')) {
            var uncheck = function() {
                setTimeout(function() {
                    $self.removeAttr('checked');
                }, 0);
            };
            var unbind = function() {
                $self.unbind('mouseup', up);
            };
            var up = function() {
                uncheck();
                unbind();
            };
            $self.bind('mouseup', up);
            $self.one('mouseout', unbind);
        }
    });

});

HTML:

<fieldset id="radioset">
    <input type="radio" id="radio-1" name="amount" value="Option 1" /><label for="radio-1" title="">Option 1</label><br />
    <input type="radio" id="radio-2" name="amount" value="Option 2" /><label for="radio-2" title="">Option 2</label><br />
    <input type="radio" id="radio-3" name="amount" value="Option 3" /><label for="radio-3" title="">Option 3</label><br />
    <input type="radio" id="radio-4" name="amount" value="Option 4" /><label for="radio-4" title="">Option 4</label><br />
    <input type="radio" id="radio-5" name="amount" value="Option 5" /><label for="radio-5" title="">Option 5</label>
</fieldset>
  • 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-26T06:22:59+00:00Added an answer on May 26, 2026 at 6:22 am

    I also tried what @Jrod did and noticed the plugin didn’t work. So I modified the plugin. Basically adding this to the label:

    .bind('mouseup', function(){
        if ($(this).is('.checked') && input.is(':radio')) {
            setTimeout(function(){
                label.removeClass('checked focus');
                input.removeAttr('checked').blur();
            }, 0);
        }
    });
    

    Here is an updated demo.

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

Sidebar

Related Questions

I've been looking for a Classic ASP script that allows me to hash a
I’m looking for a script that allows me to define my database relations in
I am looking to create a donate and Dowload script that allows you to
I am looking for an MSBuild task/script that will allow me to control the
I looking for a script that will enable me to select an area in
Im looking for a script that will take OData feed and download some .wmv
I'm looking for a script that will generate jpg thumbnails on the fly (in
I'm looking for a script/tool that can be customized to check and enforce coding/naming
I'm looking for a little shell script that will take anything piped into it,
I'm looking for a Unix shell script that will truncate all tables in a

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.