I have a Page1 with form with several elements. When i click on one of the element, it takes me to Page2(select an item in Page2) and pass that selected item as a query string back to Page1. I would then append that item in the last clicked element. It works up to this point.
Now, the issue is when i repeat the same thing i.e. click on another element, go to another page, and append that item to Page1, i can't get the previous appended items on those elements.
So, i thought of using localStorage to save the jquery objects, then use that localStorage to retrieve back those selected items with every refresh (after coming from another page).
<form>
  <div class="items" id="a">A</div>
  <div class="items" id="b">B</div>
  <div class="items" id="c">C</div>
</form>
//return querystring parameter
function GetURLParameter(sParam)
{    
    var fullQueryString = window.location.search.substring(1);    
    var sURLVariables = fullQueryString.split('&');    
    for (var i = 0; i < sURLVariables.length; i++)
    {
        var sParameterName = sURLVariables[i].split('=');
        if (sParameterName[0] == sParam)
        {
            return sParameterName[1];
        }
    }          
}
$(function(){
  arrImg = [];    
  var clickId = // function that returns the div element that is selected
  var id = GetURLParameter('id');
  if (id === 'item1') {
        var img1 = $("<img id='item1' src='' />");
        $('#' + clickId).append(img1);
        var obj = $('#' + clickId).html();
        arrImg.push(obj);
    }    
    else if (id === 'item2') {
        var img2 = $("<img id='item2' src='' />");
        $('#' + clickId).append(img2);
        var obj = $('#' + clickId).html();
        arrImg.push(obj);
    }    
    else if (id === 'item3') {
        var img3 = $("<img id='item3' src='' />")   
        $('#' + clickId).append(img3);
        var obj = $('#' + clickId).html();
        arrImg.push(obj);
    }
    localStorage.setItem("ImgCookie", JSON.stringify(arrImg));
});
I get ImgCookie: "Item1" only. Can't see other Item objects getting pushed.
 
     
    