Skip to content

Instantly share code, notes, and snippets.

@jhned
Created April 29, 2014 20:20
Show Gist options
  • Save jhned/70c36d1402b969231960 to your computer and use it in GitHub Desktop.
Save jhned/70c36d1402b969231960 to your computer and use it in GitHub Desktop.
Give the label of a radio button a checked class when the input changes.
jQuery(function($) {
$(':radio').change(function () {
// First, clear out all radio buttons
$(':radio[name=' + this.name + ']').parent().removeClass('checked');
// Add the checked class to the parent. (probably a label)
$(this).parent().addClass('checked');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment