Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

How would I get the text "Pre-Payment" from this using Jquery?

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
232 views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...