I have a div that hides and shows based on a button click. This works perfectly but I'd like to be able to do this based on a check box being ticked or not.
<html>
<head>
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
</head>
<body>
<div id="box" class="box">
<table border="1" cellpadding="1" cellspacing="1" style="width: 500px;">
<tbody>
<tr>
<td>test text</td>
<td>1</td>
</tr>
<tr>
<td>in dummy</td>
<td>2</td>
</tr>
<tr>
<td>table</td>
<td>3</td>
</tr>
</tbody>
</table>
</div>
<button>TOGGLE VISIBILITY</button>
<input type="checkbox" id="2" name="display" value="Y">
<script>
try {
var box = $('#box');
$('button').on('click', function() {
if (box.hasClass('hidden')) {
box.removeClass('hidden');
setTimeout(function() {
box.removeClass('visuallyhidden');
}, 20);
} else {
box.addClass('visuallyhidden');
box.one('transitionend', function(e) {
box.addClass('hidden');
});
}
});
} catch (error) {
throw error;
}
</script>
</body>
</html>
This example looks at the button but I'd like it to reference the status of the checkbox