JavaScript Add class to selected radio button

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.

Answer:1

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

Answer:2

I am building an offline functionality for a Cordova app that I am developing and I have a php file that gets only the list of images and I have taken the JSON from it and saved in the client device ...

I am building an offline functionality for a Cordova app that I am developing and I have a php file that gets only the list of images and I have taken the JSON from it and saved in the client device ...

I'm working on a project, and we use a lot of coding languages for different parts. I've tried to simplify the problem as much as I can, and came up with the following JSfiddle. The problem is, I ...

I'm working on a project, and we use a lot of coding languages for different parts. I've tried to simplify the problem as much as I can, and came up with the following JSfiddle. The problem is, I ...

  1. passing json string as query parameter
  2. passing json string to restful web service
  3. passing json string in url
  4. passing json string to mvc controller
  5. passing json string to spring mvc controller
  6. passing json string to javascript function
  7. passing json string as parameter to webmethod
  8. passing json string to render_template in flask
  9. passing json string to jsp
  10. passing json string
  11. passing json string in java
  12. send json string in post request
  13. send json string in post request c#
  14. send json string in get request
  15. send json string in postman
  16. send json string in post request java
  17. send json string in post request javascript
  18. send json string
  19. send json string ajax jquery
  20. send json string in post request postman

I'm working on my first GatsbyJS project (and hosted on Netlify) and over the past few weeks have noticed that everything is very speedy during development, but when built and hosted the pages are ...

I'm working on my first GatsbyJS project (and hosted on Netlify) and over the past few weeks have noticed that everything is very speedy during development, but when built and hosted the pages are ...

here i didn't understand what happen when i use var before variable in function it give me different out put and with out using var also i got a different output here is a code that you can easily ...

here i didn't understand what happen when i use var before variable in function it give me different out put and with out using var also i got a different output here is a code that you can easily ...

  1. explain value chain analysis
  2. explain value
  3. explain value added tax
  4. explain value chain
  5. explain value education
  6. explain value engineering with examples
  7. explain value of biodiversity
  8. explain value chain model
  9. explain value analysis
  10. explain value for money
  11. explain value engineering
  12. explain value proposition
  13. explain value added method
  14. explain value stream mapping
  15. explain value addition
  16. explain value at risk
  17. explain value chain analysis with example
  18. explain value based pricing
  19. explain value of information
  20. explain value and address operator in c