Last active
September 16, 2016 17:49
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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