Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7798883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:07:43+00:00 2026-06-02T00:07:43+00:00

I’ve written a cookie-based toggle show/hide menu. It remembers what was open/closed using the

  • 0

I’ve written a cookie-based toggle show/hide menu. It remembers what was open/closed using the jQuery cookie plugin. It exactly works fine; the only problem is I have to add different script for each menu. So each menu has its own script.

This is the code so far:

jQuery

$(document).ready(function() {
var panel = $("#f1_fold");
var button = $("#f1_fold_i");
var initialState = "expanded";
var activeClass = "hidden";
var visibleText = "<img src='html/sys-img/min.gif' alt='-' />";
var hiddenText = "<img src='html/sys-img/plus.gif' alt='+' />";


if($.cookie("panelState1") == undefined) {
    $.cookie("panelState1", initialState);
}
var state = $.cookie("panelState1");
if(state == "collapsed") {
    panel.hide();
    button.html(hiddenText);
    button.addClass(activeClass);
}

button.click(function(){
    if($.cookie("panelState1") == "expanded") {
        $.cookie("panelState1", "collapsed");
        button.html(hiddenText);
        button.addClass(activeClass);
    } else {
        $.cookie("panelState1", "expanded");
        button.html(visibleText);
        button.removeClass(activeClass);
    }
    panel.slideToggle("1000");
    return false;
});
});

And here is the HTML snippet

<div class="tableborder"> 
      <div class='maintitle'> 
      <div style='float: right; width: auto !important; padding-right: 6px; padding-left: 3px;'><a id='f1_fold_i' id='1' href='#' style='vertical-align:middle; border:0px solid #000; cursor:pointer;' /><img src='html/sys-img/min.gif' alt='-' /></a></div> 
<div><img src='style_images/1/nav_m.gif' border='0'  alt='&gt;' width='8' height='8' />&nbsp;<a href="index.php?c=1">Gotei 13</a></div> 
</div> 
      <span id='f1_fold' style='display:;'> 
      <table width="100%" border="0" cellspacing="1" cellpadding="4">  
        <tr>
          <th align="left" colspan="2" width="59%" class='titlemedium'>Forum</th> 
          <th align="right" width="14%" class='titlemedium'>Stats</th> 
          <th align="left" width="25%" class='titlemedium'>Last Post Info</th> 
        </tr> 
<tr> 
          <td class="row4" align="center"><img src='subnonew.gif' border='0'  alt='No New Posts' /></td>   
          <td class="row4"><b class="dtitle"><a href="index.php?showforum=1">Rules &amp; Announcement Board</a></b><br /><span class="desc">Pengumuman, panduan, dan peraturan forum dipajang di sini. Baru daftar? Yuk tengok dulu sebelum posting~<br /></span></td> 
          <td class="row2" align="right">58 Topics <br />1410 Replies</td> 
          <td class="row2" nowrap="nowrap"> 
<a href='index.php?showtopic=2069&amp;view=getlastpost' title='Go to last post'><img src='http://209.85.62.23/style_images/1/lastpost.gif' border='0'  alt='Last Post' /></a> 
Today at 01:59 am<br />In:&nbsp;<a href='index.php?showtopic=2069&amp;view=getnewpost' title='[INFO] Gelar Jepang UI 2011 (Go to first unread)'>[INFO] Gelar Jepang UI 2011</a><br />By: <a href='index.php?showuser=1'>Xaliber</a> <br />Thread: <a href='index.php?showforum=36'>Gathering &amp; Events</a></td> 
        </tr> </table></span><table width="100%"><tr> 
          <td class='darkrow2' colspan="5">&nbsp;</td> 
        </tr> 
      </table> 

    </div> 

Notice that I have to add different script for each menu because it depends on the f1_fold and f1_fold_i css ID. For the other menu, it would be f2_fold and f2_fold_i. For the other, it’d be f3_fold and f3_fold_i. Etc.

Also, to make the cookie remembers which menu is collapsed and which menu is opened, it also depends on the panelState1 (for 1st menu), panelState2 (for the 2nd), panelState3, etc

Is there any way to make this shorter and more flexible? So I don’t have to add different variable

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T00:07:44+00:00Added an answer on June 2, 2026 at 12:07 am

    After a year, though not achieving exactly what I meant, I found that using the collapsible jQuery plugin is more practical.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.