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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:55:59+00:00 2026-06-06T06:55:59+00:00

Is there an easy way to attach a deselect event on a radio button?

  • 0

Is there an easy way to attach a “deselect” event on a radio button? It seems that the change event only fires when the button is selected.

HTML

<input type="radio" id="one" name="a" />
<input type="radio" id="two" name="a" />

JavaScript

$('#one').change(function() {
    if(this.checked) {
        // do something when selected
    } else { // THIS WILL NEVER HAPPEN
        // do something when deselected
    }
});​

jsFiddle
​

  • 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-06-06T06:56:00+00:00Added an answer on June 6, 2026 at 6:56 am

    Why don’t you simply create a custom event like, lets say, deselect and let it trigger on all the members of the clicked radio group except the element itself that was clicked? Its way easier to make use of the event handling API that jQuery provides that way.

    HTML

    <!-- First group of radio buttons -->
    <label for="btn_red">Red:</label><input id="btn_red" type="radio" name="radio_btn" />
    <label for="btn_blue">Blue:</label><input id="btn_blue"  type="radio" name="radio_btn" />
    <label for="btn_yellow">Yellow:</label><input id="btn_yellow" type="radio" name="radio_btn" />
    <label for="btn_pink">Pink:</label><input id="btn_pink"  type="radio" name="radio_btn" />
    <hr />
    <!-- Second group of radio buttons -->
    <label for="btn_red_group2">Red 2:</label><input id="btn_red_group2" type="radio" name="radio_btn_group2" />
    <label for="btn_blue_group2">Blue 2:</label><input id="btn_blue_group2"  type="radio" name="radio_btn_group2" />
    <label for="btn_yellow_group2">Yellow 2:</label><input id="btn_yellow_group2" type="radio" name="radio_btn_group2" />
    <label for="btn_pink_group2">Pink 2:</label><input id="btn_pink_group2"  type="radio" name="radio_btn_group2" />
    

    jQuery

    // Attaching click event handlers to all radio buttons...
    $('input[type="radio"]').bind('click', function(){
        // Processing only those that match the name attribute of the currently clicked button...
        $('input[name="' + $(this).attr('name') + '"]').not($(this)).trigger('deselect'); // Every member of the current radio group except the clicked one...
    });
    
    $('input[type="radio"]').bind('deselect', function(){
        console.log($(this));
    })
    

    ​Deselection events will trigger only among members of the same radio group (elements that have the same name attribute).

    jsFiddle solution

    EDIT: In order to account for all possible placements of the attached label tag (wrapping the radio element or being attached through an id selector) it is perhaps better to use onchange event to trigger the handlers. Thanks to Faust for pointing that out.

    $('input[type="radio"]').on('change', function(){
        // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there an easy way of getting the datetime of the last change to
Is there an easy way in javascript to only escape certain ranges of control
Is there an easy way to calculate the derivative of non-liner functions that are
Is there an easy way to change the author of a node to another
Is there easy way to change look and feel of your WPF app, just
Is there an easy way to query a cluster for all vertices that have
Is there an easy way to log PHP errors to a log for a
Is there an easy way to generate docs for REST api direct from a
Is there an easy way to remove the character at a certain position in
Is there an easy way to use UIElement.Effect in WPF to shift the color

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.