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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:35:52+00:00 2026-05-25T15:35:52+00:00

I’m styling my input[type=radio]’s with CSS, because I need to replace the default radio

  • 0

I’m styling my input[type=radio]’s with CSS, because I need to replace the default radio with an image.
Actually what I am doing is hide the input element, and show the styled label with the image background.

To do this I’m using new CSS3 selectors “#myinputradio + label” and “myinputradio:checked + label”.
All works well using the last versions of each browser (including IE9), but I need to get it working up to IE7.

I can also refer on JQuery, but I’d like to exploit the same CSS selector for JS and CSS3-ready browsers (I have a lot of radio inputs and each one has its own background image, placed from a common sprite).

Is there any way to do this supporting also older browsers?

Here a sample from HTML:

<input id="euro" type="radio" value="euro" checked="" name="currency">
<label for="euro"></label>

And here the CSS used to style it:

#euro + label /*and all other checkboxes*/ {
    display: inline-block;
    width: 37px;
    height: 37px;
    background: url(../img/sprites.png);
}

#euro + label {
    background-position: 1042px 898px;
}

#euro:checked + label {
    background-position: 1108px 898px;
}

If you need more informations, please ask me.
Thanks.

  • 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-25T15:35:52+00:00Added an answer on May 25, 2026 at 3:35 pm

    This should work very well (Fiddle: http://jsfiddle.net/p5SNL/):

    //Loops through each radio input element
    $('input[type="radio"]').each(function(){
    
        // Checks if the next element is a label, and whether the RADIO element 
        //  has a name or not (a name attribute is required)
        if(/label/i.test($(this).next()[0].tagName) && this.name){
    
            // Adds an onchange event handler to the RADIO input element
            // THIS FUNCTION will ONLY run if the radio element changes value
            $(this).change(function(){
    
                // Loop through each radio input element with the a name attribute
                //  which is equal to the current element's name
                $('input[type="radio"][name="'+this.name+'"]').each(function(){
    
                    /*****
                     * The next line is an efficient way to write:
                     * if(this.checked){ // Is this element checked?
                     *     // Adds "labelChecked" class to the next element (label)
                     *     $(this).next().addClass("labelChecked");
                     * } else {
                     *     //Removes "labelChecked" class from next element (label)
                     *     $(this).next().removeClass("labelChecked");
                     * }
                     *****/
                    $(this).next()[this.checked?"addClass":"removeClass"]("labelChecked");
    
                    /* Alternatively, setting the CSS background:
                     * CSS background = IF "radio checked?" THEN "green" ELSE "red"
                    $(this).next().css("background", this.checked?"green":"red");
                     */
                });
    
            }); //end of event handler declaration
    
            //Adds "labelChecked" class to the current element IF it's checked
            if(this.checked) $(this).next().addClass("labelChecked");
            /*Alternative way, setting a CSS background instead of a className:
            if(this.checked) $(this).next().css("background", "green");
             */
    
        } //end of IF
    
    }); //end of the loop through all RADIO elements
    

    Note that I have deliberately added the wrong for attribute at the last label (fiddle), to show what does (and should) happen when you attach the wrong for attribute to a label.

    EDIT

    Read the comments for the explanation of the code. I have added an alternative way to define a style inside comments (2x).

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

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I need a function that will clean a strings' special characters. I do NOT
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.