I'm storing an <a>
element in localstorage and trying to get it back in a function which runs on window.onload event. Problem is, after storing that element I get [object Object] and when I apply jquery on it, it throws exception. I'm trying to get its parent here. Could anybody help me
My code:-
$('a').on('click', function(){
localStorage.setItem('link', $(this));
})
window.onload=function(){
var link = localStorage.getItem('link'); //gives [object Object]
var parent = $(link).parent(); //got error here
}
I'm storing that link so that I could add 'active' class to it and its parent elemnt on page reload/refresh. On load I want them to be active in side menubar. my sidebar menu:-
<ul>
<li id="1">
<ul><li><a href="/pages/1"></a></li><li><a href="/pages/2"></a></li></ul>
</li>
<li id="1">
<ul><li><a href="/pages/3"></a></li><li><a href="/pages/4"></a></li></ul>
</li>
</ul>