Last active
November 17, 2016 04:47
-
-
Save chuyskywalker/297981efc1be4fc5438d53adb9b93118 to your computer and use it in GitHub Desktop.
Simpler JS for you
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
// 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