i'm using jquery to collapse and expand a some div tags in my page.. my problem is that if i have a div that is collapsed and i fire an event in the back end code the page refreshes and the div expands... does anyone have any idea how can i fix this? note that i'm using asp.net with vb.net <div class="content-module-heading cf"><h3 class="fl">Table of content to send</h3><span class="fr expand-collapse-text">Click to collapse</span><span style="display: none;"class="fr expand-collapse-text initial-expand">Click to expand</span></div> Code (markup): jquery: $(document).ready(function(){ //Content boxes expand/collapse $(".initial-expand").hide(); $("div.content-module-heading").click(function(){$(this).next("div.content-module-main").slideToggle(); $(this).children(".expand-collapse-text").toggle();}); }); Code (markup):
If you want to keep the state between page refreshes, you need some way for jQuery to know the state - since javascript is client side, you don't really have that many options to save state - what you can do is use the jQuery.cookie.js plugin, and add a cookie for each toggle you're doing - and then check on the page code if there is a cookie set, and what state it's in, and toggle the visibility based on that.