Get identification value from a set of radio buttons

I am trying to get id from a set of radio buttons. Here is the HTML for it.

<input id="1" type="radio" title="2" value="6/1/2010" name="vacationDay">
<input id="2" type="radio" title="2" value="6/2/2010" name="vacationDay">
<input id="3" type="radio" title="2" value="6/3/2010" name="vacationDay" checked='checked'>

Here is my Javascript.

var updateDay = $('input[name=vacationDay]:checked').val();

It returns the value (6/3/2010) of the selected switch. I would also like to get the identifier of the checked button (3). Ideas?

+3
source share
5 answers
var $radio = $('input[name=vacationDay]:checked');
var updateDay = $radio.val();
var id = $radio.attr('id');

. attr ()

+12
source
   var btnId = $('input[name=vacationDay]:checked').attr('id');
+3
source

, , :

var id = $('input[name=vacationDay]:checked').attr('id');
+3

.val() .attr('id')!

var updateDay = $('input[name=vacationDay]:checked').attr('id');​
+2

var updateDay = $('input [name = vacationDay]: checked'). attr ('id')

0

Source: https://habr.com/ru/post/1753921/


All Articles