How Can I get the text of the selected radio in the radio groups

Michael picture Michael · Jan 25, 2010 · Viewed 26.4k times · Source

as said in the title for example:

<input id="User_Type_0" type="radio" name="User_Type" value="1" checked="checked" />
<label for="User_Type_0">User1</label>
<input id="User_Type_1" type="radio" name="User_Type" value="2" />
<label for="User_Type_1">User2</label>

how can I get the text:User 1

Answer

Darin Dimitrov picture Darin Dimitrov · Jan 25, 2010

$('input:radio:checked').siblings('label:first').html()


UPDATE:

As pointed out by Victor in the comments section the previous selector will always select the first label. The next function should work:

$('input:radio:checked').next('label:first').html()