Skip to content

Instantly share code, notes, and snippets.

@thadeu
Last active September 16, 2016 17:49
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 thadeu/bf5e9dadd2653e82537a8b87fdb62c49 to your computer and use it in GitHub Desktop.
Save thadeu/bf5e9dadd2653e82537a8b87fdb62c49 to your computer and use it in GitHub Desktop.
Útil para retirar o checked do input[type=radio] quando o mesmo está selecionado
/**
* Ao clicar perde o checked, se estiver checked
*/
$('.radio').on('click', function(e){
var $this = $(this);
if ($this.data('checked')) {
$this.prop('checked', false);
$this.data('checked', false);
$this.removeAttr('checked');
$this.trigger('change');
} else {
$this.data('checked', true);
$this.closest('form').find('[name="' + $this.prop('name') + '"]').not($this).data('checked', false);
$this.trigger('change');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment