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
  • 51,252
  • 26
  • 196
  • 186
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
  • 413,451
  • 75
  • 717
  • 787
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,179
  • 15
  • 64
  • 98
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
  • 68,720
  • 11
  • 89
  • 123