this is my sample code
var myCookie;
var initial_arr = new Array();
var myCookie_arr = new Array();
var cookieItem;
$(function() {
...
/* This quite works but can't actually achieve what I want */
$('#add_item').click(function(){
initial_arr.push(msg.txt);
//Update new cookie
$.cookie('cookieItem', initial_arr, { expires: 1});
//append on click
$('#item-list').append(msg.txt);
});
/* This is what I intend to do */
//Update new cookie
$.cookie('cookieItem', msg.txt, { expires: 1});
// add elements at the end of my cookie array
myCookie_arr.push($.cookie('cookieItem'));
...
$(window).load(function() {
...
alert(myCookie_arr);
for(var i= 0; i < myCookie_arr; i++) {
//append on visiting other pages
$('#item-list').append(myCookie_arr[i]);
}
...
if(cookieItem) {
$('#item-list').append($.cookie('cookieItem'));
} else {
$('#cat').hide();
}
});
});