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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:40:32+00:00 2026-05-28T03:40:32+00:00

I am using JQuery and custom images for custom radio buttons. Right now, it

  • 0

I am using JQuery and custom images for custom radio buttons. Right now, it would work as a checkbox. I need it to work as a radio.

When I click on either of both radio’s both will get ticked instead of one at a time. Am I missing something?

HTML:

<label for="radio1">
    <img src="radio_unchecked.png" style="vertical-align:middle" />
    <input name="radiogroup" type="radio" id="radio1" style="display:none;">
</label>

<label for="radio2">
    <img src="radio_unchecked.png" style="vertical-align:middle" />
    <input name="radiogroup" type="radio" id="radio2" style="display:none;">
</label>

JavaScript:

$(document).ready(function() {

    $("#radio1").change(function() {
        if (this.checked) {
            $(this).prev().attr("src", "radio_checked.png");
        } else {
            $(this).prev().attr("src", "radio_unchecked.png");
        }
    });


    $("#radio2").change(function() {
        if (this.checked) {
            $(this).prev().attr("src", "radio_checked.png");
        } else {
            $(this).prev().attr("src", "radio_unchecked.png");
        }
    });

});
  • 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-28T03:40:32+00:00Added an answer on May 28, 2026 at 3:40 am

    The radio buttons are working correctly (proof), but your logic for updating the images is incorrect. Both images have to change when either radio button is clicked, since both values change (and the change handler is only fired on the one that you clicked). Have a single change handler used by both radio buttons, and set both images on every change, e.g.:

    $('#radio1, #radio2').change(function() {
      var r;
    
      r = $("#radio1");
      r.prev().attr("src", r[0].checked ? checkedImage : uncheckedImage);
      r = $("#radio2");
      r.prev().attr("src", r[0].checked ? checkedImage : uncheckedImage);
    
    });
    

    Live example


    Side note: If your target browsers support the :checked pseudo-class (IE only has this as of IE9, not in IE8 or earlier) and adjacent sibling combinator from CSS3, you can do this entirely with CSS:

    HTML:

    <input type="radio" name="radiogroup" id="radio1" style="display: none">
    <label for="radio1"></label>
    <input type="radio" name="radiogroup" id="radio2" style="display: none">
    <label for="radio2"></label>
    

    CSS:

    #radio1 + label, #radio2 + label {
        display: inline-block;
        background-image: url(radio_unchecked.png);
        width: 32px;  /* Whatever matches the images */
        height: 32px; /* Whatever matches the images */
    }
    #radio1:checked + label, #radio2:checked + label {
        background-image: url(radio_checked.png);
    }
    

    Live example

    Or alternately (it’s just the selectors that are different):

    input[name="radiogroup"] + label {
        display: inline-block;
        background-image: url(radio_unchecked.png);
        width: 32px;  /* Whatever matches the images */
        height: 32px; /* Whatever matches the images */
    }
    input[name="radiogroup"]:checked + label {
        background-image: url(radio_checked.png);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is there a way to style the radio button and checkbox using custom images.
I am using a custom jQuery slider to display some images and fade through
I am using Jquery Ui plugins jquery-1.3.2.min.js and jquery-ui-1.7.1.custom.min.js and now i want to
I am using jQuery to hide the actual radio buttons on my website and
I am using jquery to create a custom dropdown with the code below. I
I'm using a custom jScrollPane and dynamically populate it using jQuery from a returned
We are using jQuery in our project. We have numerous custom javascript files in
I am using jquery validation plugin for form validation. I have added a custom
I've built a custom HTML5 audio player using jQUery according to the guide found
I am using the JQuery json plugin and trying to convert a custom object

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.