Skip to content

Instantly share code, notes, and snippets.

@chuyskywalker
Last active November 17, 2016 04:47
Show Gist options
  • Save chuyskywalker/297981efc1be4fc5438d53adb9b93118 to your computer and use it in GitHub Desktop.
Save chuyskywalker/297981efc1be4fc5438d53adb9b93118 to your computer and use it in GitHub Desktop.
Simpler JS for you
// when the document is fully loaded, run this function
$(document).ready(function(){
// find every checkbox
$('input[type="checkbox"]')
// and bind to the click method to run this function
.click(function(){
// create a variable called "box_value" which has the string from the current element's "value" attribute.
// $(this), in the current context, refers to the input-checkbox that is experiencing a click event
var box_value = $(this).attr("value");
// since the "value" matches the class name, we can start a selector $() which combines a dot and the box_value variable to form a proper class name.
// Then we toggle!
$('.'+box_value).toggle();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment