Search code examples
javascripthtmldompositioning

Is it possible to save the state of movable divs with Javascript?


So I have a page with divs which I can drag. Is it possible - without JSON or database access to save positions of these divs so that when I open the page next time they are in the same place as I left them? This is a local file so I CAN write to the file - if that is at all a consideration.


Solution

  • I suggest reading this question/answer to learn how to get the position of a div with JavaScript: Get the position of a div/span tag.

    After that, simply use JavaScript to persist the data in a cookie. Here's a decent tutorial to get you started on that.