jQuery Check if a Radio Button is Selected or not

Harsha M V

I have a table as follows and with radio buttons to select the Table Row.

<div class="table-responsive">
            <table class="table">
              <tbody>
                <tr>
                  <td>
                    <label class="radio">
                      <input type="radio" name="optionsRadios" id="optionsRadios1" value="option1" data-toggle="radio">
                    </label>
                  </td>
                  <td class="text-center"><img class="img-rounded img-responsive" alt="exaple-image" src="images/covers/02.jpg"></td>
                </tr>
                <tr class="selected-row">
                  <td>
                    <label class="radio">
                      <input type="radio" name="optionsRadios" id="optionsRadios1" value="option1" data-toggle="radio" checked>
                    </label>
                  </td>
                  <td class="text-center"><img class="img-rounded img-responsive" alt="exaple-image" src="images/covers/01.jpg"></td>
                </tr>
                <tr>
                  <td>
                    <label class="radio">
                      <input type="radio" name="optionsRadios" id="optionsRadios1" value="option1" data-toggle="radio">
                    </label>
                  </td>
                  <td class="text-center"><img class="img-rounded img-responsive" alt="exaple-image" src="images/covers/03.jpg"></td>
                </tr>
                <tr>
                  <td>
                    <label class="radio">
                      <input type="radio" name="optionsRadios" id="optionsRadios1" value="option1" data-toggle="radio">
                    </label>
                  </td>
                  <td class="text-center"><img class="img-rounded img-responsive" alt="exaple-image" src="images/covers/04.jpg"></td>
                </tr>
                <tr>
                  <td>
                    <label class="radio">
                      <input type="radio" name="optionsRadios" id="optionsRadios1" value="option1" data-toggle="radio">
                    </label>
                  </td>
                  <td class="text-center"><img class="img-rounded img-responsive" alt="exaple-image" src="images/covers/05.jpg"></td>
                </tr>
              </tbody>
            </table>
          </div>

Now when i select a a Radio Button i wanna highlight that row and remove highlight from the other rows.

// Table: Add class row selected
$('.table tbody :radio').on('check uncheck toggle', function (e) {
    var $this = $(this),
        check = $this.prop('checked'),
        toggle = e.type == 'toggle',
        checkboxes = $('.table tbody :radio'),
        checkAll = checkboxes.length == checkboxes.filter(':checked').length

        $this.closest('tr')[check ? 'addClass' : 'removeClass']('selected-row');
    if (toggle) $this.closest('.table').find('.toggle-all :radio').checkbox(checkAll ? 'check' : 'uncheck');
});

Error:

It highlights the selected row but doesnt remove hightlight from previously selected row.

Dr. McKay

Try this:

// Table: Add class row selected
$('.table tbody :radio').change(function() {
    $('.table tbody :radio:checked').closest('tr').addClass('selected-row');
    $('.table tbody :radio:not(:checked)').closest('tr').removeClass('selected-row');
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Is there a way to check if the nth radio button is selected in jQuery?

From Dev

Check for selected radio button

From Dev

Check if a radio button is selected

From Dev

jQuery After page loaded, check if radio button selected

From Dev

Check radio button | jQuery

From Dev

How do I check which radio button is selected when there are multiple radio buttons with the same name? (using jquery)

From Dev

If radio button is selected and select value is selected jquery

From Java

How to check a radio button with jQuery?

From Dev

Check if radio button exists jQuery

From Dev

Woocommerce radio button check on jquery

From Dev

Jquery check if radio button is checked

From Dev

How to check if radio buttons are selected on button click?

From Dev

How to check if the radio button is selected or not in Selenium WebDriver?

From Dev

JavaScript validation to check if a radio button is selected?

From Dev

How to check if the radio button is selected or not in Selenium WebDriver?

From Dev

Check if Radio Button is clicked (Selected) - Smarty Template

From Dev

check all radio list radio button has been selected or not on gridview

From Dev

jQuery - Check if multiple radio button groups are selected, then return name of those who aren't

From Dev

jQuery if radio button is selected then proceed to next element

From Dev

How to know which radio button is selected in jquery?

From Dev

Add jquery when radio button is selected

From Dev

jQuery - Run function/code if radio button is NOT selected

From Dev

jquery radio button selected still showing error

From Dev

Validating if the radio button group is selected JQUERY

From Dev

jQuery selected radio button index among different sets of radio buttons

From Dev

Using jQuery to check if radio button is not checked

From Dev

jquery check radio button with certain value

From Dev

JQuery Check which radio button was unchecked

From Dev

radio button check doesnt work with jquery

Related Related

  1. 1

    Is there a way to check if the nth radio button is selected in jQuery?

  2. 2

    Check for selected radio button

  3. 3

    Check if a radio button is selected

  4. 4

    jQuery After page loaded, check if radio button selected

  5. 5

    Check radio button | jQuery

  6. 6

    How do I check which radio button is selected when there are multiple radio buttons with the same name? (using jquery)

  7. 7

    If radio button is selected and select value is selected jquery

  8. 8

    How to check a radio button with jQuery?

  9. 9

    Check if radio button exists jQuery

  10. 10

    Woocommerce radio button check on jquery

  11. 11

    Jquery check if radio button is checked

  12. 12

    How to check if radio buttons are selected on button click?

  13. 13

    How to check if the radio button is selected or not in Selenium WebDriver?

  14. 14

    JavaScript validation to check if a radio button is selected?

  15. 15

    How to check if the radio button is selected or not in Selenium WebDriver?

  16. 16

    Check if Radio Button is clicked (Selected) - Smarty Template

  17. 17

    check all radio list radio button has been selected or not on gridview

  18. 18

    jQuery - Check if multiple radio button groups are selected, then return name of those who aren't

  19. 19

    jQuery if radio button is selected then proceed to next element

  20. 20

    How to know which radio button is selected in jquery?

  21. 21

    Add jquery when radio button is selected

  22. 22

    jQuery - Run function/code if radio button is NOT selected

  23. 23

    jquery radio button selected still showing error

  24. 24

    Validating if the radio button group is selected JQUERY

  25. 25

    jQuery selected radio button index among different sets of radio buttons

  26. 26

    Using jQuery to check if radio button is not checked

  27. 27

    jquery check radio button with certain value

  28. 28

    JQuery Check which radio button was unchecked

  29. 29

    radio button check doesnt work with jquery

HotTag

Archive