I have anchor element.I want to store and retrive the object in it like this way.
<a id ="test" data-val="{key1:val1,key1:val1}"> </a>
If I save in this way,while fetching it
$("#test").data('val') it gives me string like
"{key1:val1,key1:val1}".
But I am unable to parse it to json or javascript object again.
I have tried using $.parseJSON(),JSON.parse(). But it throwing an error.
How we can achive it without localstorage or sessionstorage o cookie
EDIT :
After calling $("#test").data('val')
I am getting string like this
"{'category_slug' : 'featured','tip_slug':'tip-with-all-cats'}"
If i have use $.parseJSON()or JSON.parse() it throwing an error
Uncaught SyntaxError: Unexpected token
datacache, so you don't need to callJSON.parse()on it. See this example: jsfiddle.net/cxznLctj