I'm having trouble with converting an HTML-data attribute to a Javascript Object.
Here is what I do:
The Attribute looks like:
<a id="stringObj" data-string="{'Foo':'Bar'}">Some A-Tag</a>
In Javascript / JQuery I do as followed:
var obj = $("#stringObj").data('string').replace(/'/g,"\"");
obj = JSON.stringify(obj);
obj = JSON.parse(obj);
I of just used the JSON.stringify method for clean results, but it doesn't really matter. I also tried "eval" on the result but it keeps beeing a "string" on console.log(typeof obj) test.
How do I get an object from the attribute so I could use it like alert(obj.Foo);?