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 553795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:38:33+00:00 2026-05-13T11:38:33+00:00

I’m trying to replicate a UI effect as on http://mcfc.co.uk I have written a

  • 0

I’m trying to replicate a UI effect as on http://mcfc.co.uk I have written a script that hides a div on click function and applies a class to a div with the #id corresponding to the div that was clicked, and the reverse. I’m new to jQuery, how would I save the state of these ‘clicked’ divs to a cookie to show which were hidden etc??

Thanks for any help.

<script type="text/javascript">

$(document).ready(function(){
    $('.portlet').click( function(){ 
        var idtext = this.id;
        $(this).hide();
        $("[id*=" + idtext + "]").not(this).addClass('add'); 
    });

    $("#content-footer div").click( function(){
        var idtext = this.id;   
        $(this).removeClass('add');                 
        $("[id*=" + idtext + "]").not(this).show();
    }); 
})

</script>

HTML:

DIVs that are hidden/shown on click…..

<div class="column" id="col0">

<div class="portlet" id="p_0">
  <div class="portlet-header">Feeds</div>
  <div class="portlet-content">Lorem ipsum dolor sit amet, consectetuer adipiscing elit
  </div>
</div>
<div class="portlet" id="p_1">
  <div class="portlet-header">News</div>
  <div class="portlet-content">Lorem ipsum dolor sit amet, consectetuer adipiscing elit
  </div>
</div>

</div>

etc....

DIV’s that class is applied to…..

<div id="content-footer">
  <div id="p_0"></div>
  <div id="p_1"></div>
  <div id="p_2"></div>
  <div id="p_3"></div>
  <div id="p_4"></div>
</div>
  • 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-05-13T11:38:33+00:00Added an answer on May 13, 2026 at 11:38 am

    I posted a demo of what I think you want here. Be sure to include the jQuery cookie plugin.

    Here is the HTML I used:

    <div class="column" id="col0">
    
    <div class="portlet" id="p_0">
      <div class="portlet-header">Feeds</div>
      <div class="portlet-content">Lorem ipsum dolor sit amet, consectetuer adipiscing elit</div>
    </div>
    <div class="portlet" id="p_1">
      <div class="portlet-header">News</div>
      <div class="portlet-content">Lorem ipsum dolor sit amet, consectetuer adipiscing elit</div>
    </div>
    <div class="portlet" id="p_2">
      <div class="portlet-header">Extra</div>
      <div class="portlet-content">Lorem ipsum dolor sit amet, consectetuer adipiscing elit</div>
    </div>
    <div class="portlet" id="p_3">
      <div class="portlet-header">Other</div>
      <div class="portlet-content">Lorem ipsum dolor sit amet, consectetuer adipiscing elit</div>
    </div>
    <div class="portlet" id="p_4">
      <div class="portlet-header">Last</div>
      <div class="portlet-content">Lorem ipsum dolor sit amet, consectetuer adipiscing elit</div>
    </div>
    
    </div>
    
    <div id="content-footer">
      <div name="p_0">p0 - Feeds</div>
      <div name="p_1">p1 - News</div>
      <div name="p_2">p2 - Extra</div>
      <div name="p_3">p3 - Other</div>
      <div name="p_4">p4 - Last</div>
    </div>
    

    And the script:

    $(document).ready(function(){
     var cookie = $.cookie("hidden");
     var hidden = cookie ? cookie.split("|").getUnique() : [];
     var cookieExpires = 7; // cookie expires in 7 days, or set this as a date object to specify a date
    
     // Remember content that was hidden
     $.each( hidden, function(){
      var pid = this; //parseInt(this,10);
      $('#' + pid).hide();
      $("#content-footer div[name='" + pid + "']").addClass('add');
     })
    
     // Add Click functionality
     $('.portlet').click(function(){
      $(this).hide();
      $("#content-footer div[name=" + this.id + "]").addClass('add');
      updateCookie( $(this) );
     });
     $("#content-footer div").click(function(){
      $(this).toggleClass('add');
      var el = $("div#" + $(this).attr('name'));
      el.toggle();
      updateCookie( el );
     });
    
     // Update the Cookie
     function updateCookie(el){
      var indx = el.attr('id');
      var tmp = hidden.getUnique();
      if (el.is(':hidden')) {
       // add index of widget to hidden list
       tmp.push(indx);
      } else {
       // remove element id from the list
       tmp.splice( tmp.indexOf(indx) , 1);
      }
      hidden = tmp.getUnique();
      $.cookie("hidden", hidden.join('|'), { expires: cookieExpires } );
     }
    }) 
    
    // Return a unique array.
    Array.prototype.getUnique = function() {
     var o = new Object();
     var i, e;
     for (i = 0; e = this[i]; i++) {o[e] = 1};
     var a = new Array();
     for (e in o) {a.push (e)};
     return a;
    }
    
    // Fix indexOf in IE
    if (!Array.prototype.indexOf) {
     Array.prototype.indexOf = function(obj, start) {
      for (var i = (start || 0), j = this.length; i < j; i++) {
       if (this[i] == obj) { return i; }
      }
      return -1;
     }
    }
    

    Update: Added “indexOf” prototype at the end of the script above to fix an IE bug

    Update #2: Added cookieExpires variable, use a number to set the number of days, set it as a date() to set an end date or “null” to set it as a session cookie.

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

Sidebar

Ask A Question

Stats

  • Questions 273k
  • Answers 273k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Those tags work fine here. Check that you don't have… May 13, 2026 at 2:13 pm
  • Editorial Team
    Editorial Team added an answer Yes, they can easily be maintained this way if I… May 13, 2026 at 2:13 pm
  • Editorial Team
    Editorial Team added an answer This seems to work: > #r "System.Xml.Linq" ;; May 13, 2026 at 2:13 pm

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want use html5's new tag to play a wav file (currently only supported
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I've got a string that has curly quotes in it. I'd like to replace
In order to apply a triggered animation to all ToolTip s in my app,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.