I have a div which is initially hidden. When clicking a certain link; the div will be shown... The function to reverse the show/hide does not seem to be called.
Here is the intialisation :
<!-- initially hide div --> <script type="text/javascript"> $(document).ready(function(){ $('#checkbox_grouped_Options').show (); var showtheoptions = true; // set boolean to false
}); </script>
<script type="text/javascript">
function showHidetheOptions() {
showtheoptions = !showtheoptions //invert value
if (!showtheoptions) { $('#checkbox_grouped_Options').hide (); showtheoptions = false; // set to current state to false }
else { $('#checkbox_grouped_Options').show (); showtheoptions = true; // set to current state to true }
First of all, use toggleClass() as suggested above. Now let's look at the reason why your initial code didn't work. Simply add the following one line at the beginning of your code and that will fix your issue:
showtheoptions = true;
Your original script failed at the following line, because showtheoptions was undefined: