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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:07:58+00:00 2026-06-02T20:07:58+00:00

I have some jQuery that sets an image as a radio button for a

  • 0

I have some jQuery that sets an image as a radio button for a star rating system. I wish to include a function that when the user cicks a radio button the image changes to checked and the previous radios are also change to checked.

I have managed to change the class of the checked button and I have some code that would change the class on the previous buttons also, but on a simpler div structure. I have been able to combine the both.

The code to change the class for the radio button

$(function() {
    $('input:radio').each(function() {
        $(this).hide();
        $('<a title=" check me " class="radio-fx '+this.name+'" href="#"><div class="radio"></div></a>').insertAfter(this);
    });
    $('.radio-fx').live('click',function(e) {
        e.preventDefault();
        $check = $(this).prev('input');
        var unique = '.'+this.className.split(' ')[1]+' div';
        $(unique).attr('class', 'radio');
        $(this).find('div').attr('class', 'radio-checked');
        $check.attr('checked', true);
    });

});

html:

                  <div class="voteGroup">
                        <input type="radio" id="price_0" value="1" name="price" style="display: none;" checked="checked">
                        <a href="#" class="radio-fx price" title=" check me ">
                            <div class="radio-checked"></div>
                        </a>
                        <input type="radio" id="price_1" value="2" name="price" style="display: none;" checked="checked">
                        <a href="#" class="radio-fx price" title=" check me ">
                             <div class="radio"></div>
                        </a>
                        <input type="radio" id="price_2" value="3" name="price" style="display: none;" checked="checked">
                        <a href="#" class="radio-fx price" title=" check me ">
                              <div class="radio"></div>
                        </a>

                    </div>

Code that I tried to integrate to set previous ones to checked on hover:

        $('.radio-fx').hover(
            // Handles the mouseover
            function() {
                $(this).prevAll().andSelf().addClass('radio-checked');
                $(this).nextAll().removeClass('radio');
            },
            // Handles the mouseout
            function() {
                $(this).prevAll().andSelf().removeClass('radio');
            }
        );

Thanks for any help.

  • 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-02T20:08:00+00:00Added an answer on June 2, 2026 at 8:08 pm
    <div class="voteGroup">
        <input type="radio" id="price_0" value="1" name="price" style="display: none;" checked="checked">
        <a href="#" class="radio-fx price" title=" check me ">
            <div class="radio"></div>
        </a>
        <input type="radio" id="price_1" value="2" name="price" style="display: none;" checked="checked">
        <a href="#" class="radio-fx price" title=" check me ">
             <div class="radio"></div>
        </a>
        <input type="radio" id="price_2" value="3" name="price" style="display: none;" checked="checked">
        <a href="#" class="radio-fx price" title=" check me ">
              <div class="radio"></div>
        </a>
    </div>
    <style type="text/css">
        .radio-fx { float:left;margin:10px;}
        .radio-fx .radio{ background:#ff0; width:20px; height:20px;}
        .radio-checked .radio{ background:#f0f;}
    </style>
    <script type="text/javascript" src="../share/libs/jquery-1.7.min.js"></script>
    <script type="text/javascript">
    $(function() {
        $('.radio-fx').live( "mouseenter", function() { // Handles the mouseover
                var $self = $(this);
                $self.addClass('radio-checked').prevAll().addClass('radio-checked');
                $self.nextAll().removeClass('radio-checked');
        }).live ( "mouseout", function() { // Handles the mouseout
                $(this).removeClass('radio').prevAll().removeClass('radio'); // what is this for?
        });
    });
    </script>
    

    complete test code here, have a try

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

Sidebar

Related Questions

I have some jQuery code that intercepts links clicked on a page: $(document).ready(function() {
I have some jQuery code. I have called an Ajax function file, file.php, that
I have some jquery code that is doing an ajax lookup and returning comma
I have some jQuery code that highlights a link when clicked, and changes the
I have some jQuery code that is having difficulty running because I'm using it
I have some jQuery code that runs fine until I add the jQuery UI
I have some jQuery/JavaScript code that I want to run only when there is
I have some HTML and jQuery that slides a div up and down to
I've been writing some jQuery functions that have JavaScript variables and looping, etc inside
I have some DIVs that I am using JQuery to hide and show using

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.