Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: jQuery
Hi,
 
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.
 
<style>
.click {
width:100px;
height:100px;
background:green;
}
</style>
<div class="click">click</div>
 
$(".click").click(function() {
        $(this).css("background","red");
}
Posted 1-Oct-12 21:58pm
Edited 1-Oct-12 22:06pm
v2
Comments
Sandeep Mewara at 2-Oct-12 4:10am
   
On refresh/reload, background color set is retained?
Peeyush Pachaori at 2-Oct-12 4:19am
   
When you click on the button do you go on server?
subhakarb at 2-Oct-12 5:37am
   
no
Rate this: bad
good
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.
  Permalink  
v2
Rate this: bad
good
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.
  Permalink  
v2

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



Advertise | Privacy | Mobile
Web02 | 2.8.140926.1 | Last Updated 2 Oct 2012
Copyright © CodeProject, 1999-2014
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