0

I am using jQuery.

I have a list of radio buttons which I am getting this way:

var $selectAllRadios = $('input:radio[value=select]');

Now in this list I want to be able to select all the radio buttons which are currently checked and also the number of radio buttons that are currently checked.

How can I achieve this?

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Sidhartha Shenoy
  • 179
  • 1
  • 13

3 Answers3

2

Use the :checked selector to grab the selected radio buttons, and the length property to find out how many there are.

var $checkedRadios = $('input:radio[value=select]:checked');
var count = $checkedRadios.length;
Jon
  • 428,835
  • 81
  • 738
  • 806
2

This is a duplicated, you should search the site before asking a question:

Radio button selected?

How to know if radio is checked

As for the number of elements you can always use the length property.

Community
  • 1
  • 1
willvv
  • 8,439
  • 16
  • 66
  • 101
2

Use this to get the length of the radio buttons that are checked.

$('input:radio[value=select]').filter(':checked').length

To get the length of radio butons that are not checked.

$('input:radio[value=select]').filter(':not(:checked)').length
ShankarSangoli
  • 69,612
  • 13
  • 93
  • 124