Skip to content

Instantly share code, notes, and snippets.

@micflan
Created March 16, 2015 22:35
Show Gist options
  • Save micflan/42f0710c3cbbd63e1c12 to your computer and use it in GitHub Desktop.
Save micflan/42f0710c3cbbd63e1c12 to your computer and use it in GitHub Desktop.
Simple jQuery reveal-on-click checkbox
//
// <input type="checkbox" class="checkboxReveals" data-reveal="#someContainer" />
// <div id="someContainer" style="display: none;"> ... </div>
//
$(function() {
var checkboxReveal = function(checkbox) {
var target = $(checkbox.data('reveal'));
if(checkbox.is(":checked")) {
target.slideDown();
} else {
target.slideUp();
}
};
$('.checkboxReveals').each(function() {
checkboxReveal($(this));
});
$('.checkboxReveals').change(function() {
checkboxReveal($(this));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment