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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:47:09+00:00 2026-05-27T22:47:09+00:00

I am trying to check the radio box onClick using jQuery, my code is

  • 0

I am trying to check the radio box onClick using jQuery, my code is below:

<ul class="icons clearfix">
    <li>
        <input type="radio" value="123456" name="selecticon"/>
        <label for="select_icon">
            <img src="pics/123456.jpg" alt="123456" width="34" height="34" />
        </label>
    </li>
    <li>
        <input type="radio" value="654321" name="selecticon" />
        <label for="select_icon">
            <img src="pics/654321.jpg" alt="654321" width="34" height="34" />
        </label>
    </li>
</ul>

and jQuery code…

//onclick select icon
$(document).ready(function(){
    $('ul.icons li').click(function() {
    $('ul.icons li.selected').removeClass('selected');
    $(this).addClass('selected').children("input[@type=radio]").attr('checked');
   });
});

But on click its not checking radio button, please suggest, 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-27T22:47:10+00:00Added an answer on May 27, 2026 at 10:47 pm

    Change:

    .attr('checked')
    

    To:

    .prop('checked', true)
    

    You could also use .attr('checked', 'checked'), but it’s suggested to use prop() for boolean attributes like checked.

    You also need quotes around the attribute value here:

    .children('input[@type="radio"]')
    

    Demo: http://jsfiddle.net/pUqBB/

    Additionally (not related), The for attribute of a <label> must match the associated input’s id rather than the name.

    Most importantly:

    You don’t need javascript for this at all if you simply wrap the whole thing in a <label>

    Demo: http://jsfiddle.net/pUqBB/1/

    See also: How can I make an HTML radiobutton with a big target area?


    EDIT: OK, not sure if you’re interested but I rewrote this with the accessible version using <label>, and js only to add/remove the selected class (since we do need javascript for that bit). I’m using this code in production on all my sites, feel free to use it (or point out improvements):

    http://jsfiddle.net/pUqBB/2/

    // Add class="selected" to the parent element of checked inputs
    
    // on page load
    $("input:checked").parent().addClass('selected');
    
    $(":radio").live('change', function () {
       if ($(this).prop('checked')) {
            $(':radio[name="' + $(this).attr('name') + '"]').parent().removeClass('selected');
            $(this).parent().addClass('selected');
        }
    });
    
    $(":checkbox").live('change', function () {
        if ($(this).prop('checked')) {
            $(this).parent().addClass('selected');
        } else {
            $(this).parent().removeClass('selected');
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the HTML code of a radio button <input type=radio class=grgrgrtgxxxxfeegrgbrg> I am
I'm trying to get the value of two radio button groups using the jQuery
I am working with input elements in a form using jquery...I am trying to
Here is my view source: <input id=ctl00_cp_ctrlNew_lendeeMe type=radio name=ctl00$cp$ctrlNew$whoBorrowed value=lendeeMe /> And I am
I'm trying to check, using an automated discovery tool, when JAR files in remote
I'm trying to check if a service exists on a remote machine using the
I was trying to check out a project from SVN using Eclipse. I tried
I'm trying to check in jQuery if a div contains some text, and then
I've got the value of a radio button (r1) and I'm trying to use:
I have a gender selection radio: <div class="label-inputs" name="userFieldDiv" id="genderUserFieldDiv"> <label class="required">Sexo</label> <input type="radio"

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.