Skip to content

Instantly share code, notes, and snippets.

@norcross
Created August 1, 2012 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save norcross/3227943 to your computer and use it in GitHub Desktop.
Save norcross/3227943 to your computer and use it in GitHub Desktop.
allow labels to set input for radio and checkbox
// **************************************************************
// set inputs when clicking labels
// **************************************************************
$('div#default_license span.ap_option label[rel="ap_rd"]').each(function() {
$(this).click(function() {
if($(this).hasClass('disabled-label'))
return;
var radio_me = $(this).prev('input');
$(radio_me).prop('checked', true);
$(radio_me).trigger('change');
});
});
$('div#default_license span.ap_option label[rel="ap_ck"]').each(function() {
$(this).click(function() {
if($(this).hasClass('disabled-label'))
return;
var check_me = $(this).prev('input');
var is_check = $(check_me).attr('checked') ? true : false;
if (is_check === false) {
$(check_me).prop('checked', true);
$(check_me).trigger('change');
}
if (is_check === true) {
$(check_me).prop('checked', false);
$(check_me).trigger('change');
}
});
});
@jtsternberg
Copy link

hmm probably safe to assume you have a specific reason for needing this, but this can be accomplished with pure html.
either:

<label><input type="radio" name="name" /> My clickable label</label>

or

<label for="name">My clickable label</label><input id="name" type="radio" name="name" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment