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

  • Home
  • SEARCH
  • 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 7177925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:48:55+00:00 2026-05-28T16:48:55+00:00

I am trying to create a user interface, but when I refresh the page,

  • 0

I am trying to create a user interface, but when I refresh the page, it’s removing the class current from navigation link.

I am following this tutorial http://www.ssdtutorials.com/tutorials/series/list-grid-view-jquery-cookies.html

Below is my code:

$(function() {
    var cc = $.cookie('list_grid');
    if (cc == 'g') {
        $('#products').addClass('grid');
    } else {
        $('#products').removeClass('grid');
    }
});

$(document).ready(function() {

    $('#grid').click(function() {
        $(".current").removeClass("current");
        $(this).addClass("current");

        $('#products').fadeOut(500, function() {
            $(this).addClass('grid').fadeIn(500);
            $.cookie('list_grid', 'g');
        });
        return false;
    });

    $('#list').click(function() {
        $(".current").removeClass("current");
        $(this).addClass("current");

        $('#products').fadeOut(500, function() {
            $(this).removeClass('grid').fadeIn(500);
            $.cookie('list_grid', null);
        });
        return false;
    });

});

In case anyone need this is the HTML code

<div id="wrapper">

        <div id="navigation">
            <a href="#" id="list">List view</a>
            <a href="#" id="grid">Grid view</a>
        </div>

        <div id="products">

            <?php for($i = 1; $i <= 4; $i++) { ?>

                <div class="product">

                    <div class="wrapper">

                        <div class="image">
                            <img src="images/0<?php echo $i; ?>.jpg" alt="image <?php echo $i; ?>" width="160" height="160" />
                        </div>

                        <div class="description">

                            <h1><a href="#">Article title</a></h1>

                            <p>Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt.</p>

                        </div><!-- end description -->

                    </div><!-- end wrapper -->

                </div><!-- end product -->

            <?php } ?>

        </div><!-- end products -->

    </div><!-- end wrapper -->
  • 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-28T16:48:56+00:00Added an answer on May 28, 2026 at 4:48 pm

    When you refresh the page, it will be reloaded in its original state. It doesn’t remember which item had the current class. You need to use something like the cookie you’re already employing if you want the page to be able to remember which element had which class added to it dynamically.

    Something like this:

    $(function() {
        var cc = $.cookie('list_grid');
        if (cc == 'g') {
            $('#products').addClass('grid');
            $('#grid').addClass('current');            
        } else {
            $('#products').removeClass('grid');
            $('#list').addClass('current');
        }
    });
    

    BTW, $(function() { ... } is a short-hand way of writing $(document).ready(function() { ... }, so you can actually combine your two functions above.

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

Sidebar

Related Questions

I am trying to create a user interface using XAML. However, the file is
Trying to create a user account in a test. But getting a Object reference
Im trying to create a user control menu where links to a page's usercontrols
I'm trying to create a User Registration page in ASP.NET and wondering what is
I am trying to create a winForms user control. But I want would like
I'm trying to create a user interface using Google Web Toolkit v2.4. For a
I'm trying to create an user interface like the one is presented in App
I'm trying to create a web user interface for a Java application. The user
I'm trying to create combobox type interface so that user can select an item
I'm trying to create user profiles for my site where the URL is something

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.