krish mandava krish mandava - 1 year ago 72
jQuery Question

Get the text of the selected radio button in JQuery

In Jquery How do I get the text (not values) for the selected radio button as shown below

<label> <input type="radio" name="Surv_Q1" value="20">5 - Excellent</label>
<label> <input type="radio" name="Surv_Q1" value="20">4 - Good</label>


I tried with the below code , but didn't work

$("input[name='Surv_Q"+i+"']:checked").next('label').text();

Answer Source

HTML:

<label> <input type="radio" name="Surv_Q1" value="20" data-name="5 - Excellent" checked="true">5 - Excellent</label>
<label> <input type="radio" name="Surv_Q1" value="20" data-name="4 - Good">4 - Good</label>

SCRIPT:

$("input[name='Surv_Q1']:checked").data('name');

OR you don't want to change in HTML then this one::

$("input[name='Surv_Q1']:checked").parent('label').text();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download