Get Text of checkbox with Jquery

You should probably have a value attribute in the checkbox.

<input type="checkbox" name="PrePayment" value="Pre-Payment">Pre-Payment<br />

Then you can simply use the attr command:

$(input).attr('value');

I'd recommend putting the text inside a <label> tag so that you could click on it (and so that screen readers and such could make sense of your form):

<input type="checkbox" name="PrePayment" id="pre-payment">
<label for="pre-payment">Pre-Payment</label>
<br />

Then, the whole thing becomes easy:

var text    = $('label[for=pre-payment]').text();
var or_this = $('#pre-payment').next('label').text();

I'd prefer the first option, label[for=...], as it is less fragile than the second


Maybe:

$("input[name='PrePayment']")[0].nextSibling.nodeValue;

Try it here.

Tags:

Html

Jquery