Click here to Skip to main content
12,897,391 members (53,858 online)
Rate this:
Please Sign up or sign in to vote.
See more: jQuery

In our HTML on click function change the div bg color, but when page refresh change the colour. I don’t want to change the color after page refresh or reload.

.click {
<div class="click">click</div>

$(".click").click(function() {
Posted 1-Oct-12 21:58pm
Updated 1-Oct-12 22:06pm
Sandeep Mewara 2-Oct-12 4:10am
On refresh/reload, background color set is retained?
Peeyush Pachaori 2-Oct-12 4:19am
When you click on the button do you go on server?
subhakarb 2-Oct-12 5:37am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

If i understand u correct, then on page refresh you want to retain the bg color. Which will not be possible as when you refresh the page it loads again. To solve this problem you need to go to the server. On load function (client) you can write code to change the bg color based on some returned flag from server which you should set after you click on button.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

If you want to keep this change just between page refresh, you can use session cookie: just store in a cookie all altered styles and apply the on page load. But if you want to keep the between sessions on different clients, you need to store the changes on the server in some sort of personal preference or business data.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 2 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100