I created dynamic list(list with hyperlink) using jquery.when I click that link fo rthe first time it will go to the next page.
I used the cookie for save the index of link value while I am clicking that link.Again run that application
get the saved index value from cookie in onload.Using that value change the color that particular link.
Now I want to I will run that application again that link is displayed in red color and the other links(unvisited) are displayed in blue color.
How to do this?
$(".sidemenu li ").click(function() {
var index = $('li').index(this);
// alert(index);
checkCookie(index);
// saveid(index);
});
}
function checkCookie(index)
{
var linkindexvalue=index;
// alert(linkindexvalue);
setCookie("indexvalue",linkindexvalue,365);
}
function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + value;
alert(document.cookie);
}
$(document).ready(function(){
var list=getCookie("indexvalue");
if(list=='1'){
alert(" ");
$(".sidemenu li").css("background-color","red");
}
});
function getCookie(c_name)
{
alert("hj");
var value = "";
var DocumentCookie = " " + document.cookie + ";";
var CookieSearchStr = " " + c_name + "=";
var CookieStartPosition = DocumentCookie.indexOf(CookieSearchStr);
var CookieEndPosition;
if (CookieStartPosition != -1) {
CookieStartPosition += CookieSearchStr.length;
CookieEndPosition = DocumentCookie.indexOf(";", CookieStartPosition);
value = unescape(DocumentCookie.substring(CookieStartPosition, CookieEndPosition));
}
return value;
}
please guide me.
Thanks in advance
There’s actually the jQuery Visited plugin that let you get the visited links in your page.
Once included, you can select the links and attach a class with the new colour:
Notice that in this case you have to add an
<a>inside your<li>s, since I don’t think the visited feature it’s strictly related to links on a anchor, not clicks on a list item.If on the contrary you need to go for the cookies options, give me some time to check your code! 🙂