You set the variable to load the page and do not refresh it when the div changes. To fix this, you can check the value instead of using a variable
$(document).ready(function () { $('div#showhidenav').click(function () { if ( $('div#navigationpanel').css('max-width') == "0px" ) { $('div#navigationpanel').css('max-width', '850px'); } else if ( $('div#navigationpanel').css('max-width') == "850px" ) { $('div#navigationpanel').css('max-width', '0px'); } }); });
But if you just want to show and hide the div, then jQuery has a built-in .toggle() function
$(document).ready(function () { $('#showhidenav').click(function () { $('#navigationpanel').toggle(); }); });
You can specify the duration and attenuation for the transition. From jQuery documentation
.toggle (duration [, easing] [, complete])
duration (default: 400) Type: Number or String A string or number determining how long the animation will run. easing (default: swing) Type: String A string indicating which easing function to use for the transition. complete Type: Function() A function to call once the animation is complete.
source share