In my HTML forms (as in most HTML forms), the labels share the same IDs as the fields. I’m trying to return to HTML of the label tag once the checkbox with a matching ID is clicked.
<input id="yes1" type="checkbox">
<label for="yes1">This is the text it should return.</label>
And my jQuery:
$('input').change(function() {
if (this.checked) {
var response = $('label#' + $(this).attr('id')).html();
}
}
But alas, response comes out as NULL.
No need to get the id from the attribute.
Demo: http://jsfiddle.net/wycvy/