Add class to selected radio button

Anoops

How do I add and remove a class only to selected radio button of a set of radio buttons?

<table class="radioClass" role="set1"><tbody><tr><td><input type="radio" value=" Yes " id="" name="j_id0:j_id37:j_id41"> label for="j_id0:j_id37:j_id41:0">  Yes </label></td><td><input type="radio" value=" No " id="" name="j_id0:j_id37:j_id41"<label for="j_id0:j_id37:j_id41:1">  No </label></td></tr></tbody></table>
 $(document).ready(function(){
    $("input[type='radio']").click(function(){
        var radioValue = $("input:checked").val();
       if(radioValue){
            //alert("Your are a - " + radioValue);
            $("input:checked").toggleClass("checked");
        }
    });

JSFiddle.

Manwal

First remove checked class from all radio buttons and then add to specific selected one. This is how you can do this:

if(radioValue){
     $("input[type='radio']").removeClass("checked");
     $(this).toggleClass("checked");
}

DEMO

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Add class to selected radio button

From Dev

add class for selected radio button in thymeleaf

From Dev

How do I add class to label when radio button is selected?

From Dev

JavaScript / jquery: add class if a radio button is selected and data attribute qualifies

From Dev

Set the class on selected radio button

From Dev

Add jquery when radio button is selected

From Dev

add class and remove class from selected button

From Dev

On click of radio button, add class to parent

From Dev

How to add checked class to a radio button in AngularJS

From Dev

How to add checked class to a radio button in AngularJS

From Dev

Add class to the label for radio button in cakephp 3

From Dev

How to add and remove class on radio button?

From Dev

How to add style to the parent when radio button is selected

From Dev

Check for selected radio button

From Dev

checking if a radio button is selected

From Dev

Radio button selected is always on

From Dev

Check if a radio button is selected

From Dev

bootstrap: change class of tr in a table when radio button selected

From Dev

How to add class to button of selected marker

From Dev

Add/Remove class of form element on radio button click

From Dev

jQuery: Add class if list item has checked radio button inside

From Dev

Add class to radio button in choice list field, orchard cms

From Dev

add and remove class when toggling through radio button

From Dev

Trying to use javascript to add unique class when radio button checked

From Dev

jQuery Check if a Radio Button is Selected or not

From Dev

MVC Radio button selected one

From Dev

Fetching selected radio button in wpf

From Dev

Getting radio button selected value

From Dev

Default Radio button selected value

Related Related

  1. 1

    Add class to selected radio button

  2. 2

    add class for selected radio button in thymeleaf

  3. 3

    How do I add class to label when radio button is selected?

  4. 4

    JavaScript / jquery: add class if a radio button is selected and data attribute qualifies

  5. 5

    Set the class on selected radio button

  6. 6

    Add jquery when radio button is selected

  7. 7

    add class and remove class from selected button

  8. 8

    On click of radio button, add class to parent

  9. 9

    How to add checked class to a radio button in AngularJS

  10. 10

    How to add checked class to a radio button in AngularJS

  11. 11

    Add class to the label for radio button in cakephp 3

  12. 12

    How to add and remove class on radio button?

  13. 13

    How to add style to the parent when radio button is selected

  14. 14

    Check for selected radio button

  15. 15

    checking if a radio button is selected

  16. 16

    Radio button selected is always on

  17. 17

    Check if a radio button is selected

  18. 18

    bootstrap: change class of tr in a table when radio button selected

  19. 19

    How to add class to button of selected marker

  20. 20

    Add/Remove class of form element on radio button click

  21. 21

    jQuery: Add class if list item has checked radio button inside

  22. 22

    Add class to radio button in choice list field, orchard cms

  23. 23

    add and remove class when toggling through radio button

  24. 24

    Trying to use javascript to add unique class when radio button checked

  25. 25

    jQuery Check if a Radio Button is Selected or not

  26. 26

    MVC Radio button selected one

  27. 27

    Fetching selected radio button in wpf

  28. 28

    Getting radio button selected value

  29. 29

    Default Radio button selected value

HotTag

Archive