Skip to content

Instantly share code, notes, and snippets.

@lizardking8610
Created May 18, 2017 17:12
Show Gist options
  • Save lizardking8610/2f07f8376cf8af550b2284dc682e6cc4 to your computer and use it in GitHub Desktop.
Save lizardking8610/2f07f8376cf8af550b2284dc682e6cc4 to your computer and use it in GitHub Desktop.
jQuery: click trigger on input when label clicked
var labelID;
$('label').click(function() {
labelID = $(this).attr('for');
$('#'+labelID).trigger('click');
});
//All browsers except IE will do this when you code it this way below:
//<label><input id='my_input'/></label>
//IE requries this:
//<label for='my_input'><input id='my_input'/></label>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment