Prevent expand when firing back end code

Discussion in 'jQuery' started by Jocelyne, Oct 2, 2013.

  1. #1
    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):
     
    Jocelyne, Oct 2, 2013 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    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.
     
    PoPSiCLe, Oct 3, 2013 IP