views:

21

answers:

2

I have javascript code which alters the width of a specified DIV. It is attached to a button so each button click adds 50px to the width attribute. But when the page is refreshed on the browser the div attribute goes back to what it was originally. This is the setWidth function:

function setWidth(){
 jQuery('.tab_panel').each(function(){
 jQuery(this).css({width: (jQuery(this).width() + 50) + 'px'});
  });
}

it is called when I click the button. How do I save the attribute to a cookie so it stays between page refreshes? Thanks

A: 

document.cookie = "divWidth=50%"

Here is a good resource on cookies in javascript: http://w3schools.com/js/js_cookies.asp

I hope that will accomplish your task.

Skyler
A: 

If you are already using jQuery, the jQuery cookie plugin will help alot: http://plugins.jquery.com/files/jquery.cookie.js.txt

digitalFresh