0
var btnlist="";
$("#divPopup").on("click", "li", function () {
    var $this = $(this);
    // get currect id an replace with right
    var newId = $this.attr('Id').replace("Left", "Right")
    // check if the image is not for True
    if ($('#' + newId).find('img').attr('class') != 'checkImage') {
        $this.toggleClass("selected");
        if ($this.attr('class') == "selected") {
            btnlist.
            $('#' + newId).show(); // <== i want to store Newid each time when.show() method ex
        }
        else {
            var newId = $this.attr('Id').replace("Left", "Right")
            $('#' + newId).hide();
        }
    }
});

i want to store btnlist.$('#' + newId).show(); <== i want to store Newid each time when.show() method execute, How can i store it.?

for example, there is 10 li element all are hidden ! , now let's see i click on 5 li element, and made them as show!

how can i create list of visiable items ? something like this var visiable = ([li1, li2, li3,li4,li5]); which line of code i need to put more to achieve something like this

Nestor C
  • 637
  • 3
  • 9
  • 14

2 Answers2

0

sessionStorage or localStorage are key/value pairs, all you have to do is:

sessionStorage.newId = newId;

You may want to check if browser is supporting it with:

if(typeofsessionStorage)!=="undefined")
{
  // storage supported
}

Update

sessionStorage and localStorage don't support arrays, but you can store your data as json strings:

sessionStorage.newIds = JSON.stringify([1, 2, 3]);
var ids = JSON.parse(sessionStorage.newIds);
Zbigniew
  • 27,184
  • 6
  • 59
  • 66
  • I'm sorry but I still don't understand, do you want to store an array inside `sessionStorage`? – Zbigniew Mar 16 '13 at 10:10
  • Yes,right i want all visible li elements, may be array is option – Nestor C Mar 16 '13 at 10:12
  • Check my edited answer, unfortunetly it seems that it makes it a dupicate of [this question](http://stackoverflow.com/questions/3357553/how-to-store-an-array-in-localstorage), am I right? – Zbigniew Mar 16 '13 at 10:18
0

You can use Amplifyjs Store Plugin.

From documentation :

amplify.store is a wrapper for various persistent client-side storage systems. amplify.store supports IE 5+, Firefox 2+, Safari 4+, Chrome, Opera 10.5+, iPhone 2+, Android 2+ and provides a consistent API to handle storage cross-browser.

Sample Usage :

amplify.store(key, value)       // => store the value on the given key

var value = amplify.store(key); // => extract the value on the given key

EDIT

For storing values in HTML5 session storage you should check out this link :

http://www.nczonline.net/blog/2009/07/21/introduction-to-sessionstorage/

EDIT-2

I have created a fiddle in which you can see a code for accessing all li items and how to save clicked items.

Working Fiddle

Gaurav
  • 8,367
  • 14
  • 55
  • 90
  • Thanks For reply :) , but i am not looking for storage , i want all visiable items and store them in html 5 session storage – Nestor C Mar 16 '13 at 10:14
  • But i am really not looking for the way the storing part, i need list of IDs when i click !, that's all sir :( – Nestor C Mar 16 '13 at 10:20
  • @NestorC can you please EDIT your question and specifically define what you actually want – Gaurav Mar 16 '13 at 10:30
  • @NestorC please check the updated answer `(EDIT-2)`, i created a fiddle according to what i understood from you edit, hope this time it helps – Gaurav Mar 16 '13 at 10:59