PDA

View Full Version : changes to LI disappear when page is refreshed


IWreck86
12-30-2009, 08:44 PM
Hello,

This is not a huge problem but I was noticing that the changes I was making to a LI's class name (using document.getElementById('id').className) was being undone when the page was refreshed. Is there a way to keep the current className when the page is refreshed instead of the changes being undone?

Here's an example of my code (shorthand version):

<li id="listitem" class="" onclick="this.className='selected'">blah</li>

Thanks for the help!

abduraooft
12-31-2009, 07:39 AM
Yes, that's normal. What exactly you are doing in your page?

Daybreak0
12-31-2009, 11:26 PM
I have no idea of javascript (but getting a little) but can you on refresh, get the state of the object, and then reset it to that state.

Arbitrator
01-01-2010, 03:46 AM
I have no idea of javascript (but getting a little) but can you on refresh, get the state of the object, and then reset it to that state.You can't make persistent changes with ECMAScript/JavaScript without communicating with a server. The most you can do with this kind of scripting is look at the URL and use the script to dynamically change the document based upon it.

sohighthesky
01-18-2010, 05:22 AM
hope this can be helpful:https://developer.mozilla.org/en/DOM/Storage

or you can use cookie to save the which <li> is selected,