Created
July 31, 2018 17:10
-
-
Save lucasstark/919b22ab0c7a751dd8373674749eabb0 to your computer and use it in GitHub Desktop.
This file contains 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
(function($) { | |
$(document).ready(function() { | |
$("input[type=radio]").click(function() { | |
// Get the storedValue | |
var previousValue = $(this).data('storedValue'); | |
// if previousValue = true then | |
// Step 1: toggle radio button check mark. | |
// Step 2: save data-StoredValue as false to indicate radio button is unchecked. | |
if (previousValue) { | |
$(this).prop('checked', !previousValue); | |
$(this).data('storedValue', !previousValue); | |
} | |
// If previousValue is other than true | |
// Step 1: save data-StoredValue as true to for currently checked radio button. | |
// Step 2: save data-StoredValue as false for all non-checked radio buttons. | |
else{ | |
$(this).data('storedValue', true); | |
$("input[type=radio]:not(:checked)").data("storedValue", false); | |
} | |
}); | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment