0

I am using the below code to get all the checked radio buttons under a div element. But its not working. I think I am doing something wrong.

#divElement input[type="radio"]:checked
A Paul
  • 8,113
  • 3
  • 31
  • 61
  • 2
    please share your html code also – Bhushan Kawadkar Feb 17 '15 at 07:49
  • Isn't the purpose of a radio button, you select only one? – Steven Feb 17 '15 at 07:51
  • Yes Steven, I have multiple radio buttons, just want to know which one is selected. But it is a common code want to work for checkbox also – A Paul Feb 17 '15 at 07:52
  • possible duplicate of [How can I get which radio is selected via jQuery?](http://stackoverflow.com/questions/596351/how-can-i-get-which-radio-is-selected-via-jquery) – Ian Wang Feb 17 '15 at 07:59
  • Look at this example (the same selector but used with css): http://jsfiddle.net/qvm6qz04/ – Al.G. Feb 17 '15 at 08:02
  • This question is not very clear. What do you want to achieve? Your selector appears ok to me for what you ask. I guess you want to do something after selecting them, but that is not stated.. – Steven Feb 17 '15 at 08:30

2 Answers2

1

.val() property will give you selected radio button value.

$('#divElement input[type="radio"]:checked').val();

Demo

Sadikhasan
  • 18,365
  • 21
  • 80
  • 122
1
 $('#divElement input').on('change', function() {
       alert($('input[type=radio]:checked', '#divElement ').val()); 
    });

this way you can get the value of selected radio.Also your question is not clear whether it wants list of selected radios or just one?

Utkarsh
  • 384
  • 3
  • 6