If you use valid JSON ([
and ]
for the array, double quotes instead of single), like this:
<div id="locations" data-locations="[{"name":"Bath","url":"/location/bath","img":"/thumb.jpg"},{"name":"Berkhamsted","url":"/location/berkhamsted","img":"/thumb.jpg"}]">
Then what you have (using .data()
) to get the array will work:
$('#locations').data('locations');