I'm passing some values to a javascript function from an anchor tag as follows:
<a href="http:///www.example.com" data-json='{ "next_id": 3, "prev_id":1}' id="2">Click here</a>
The js function looks a bit like this:
$(document).on( 'click', 'a', function( event ) {
console.log($(this).data());
var this_id = this.id;
var next_id = $(this).data(next_id);
var prev_id = $(this).data(prev_id);
}
The console shows the following for $(this).data()
Object {json: Object}
json: Object
next_id: 3
prev_id: 1
But any attempt to read the values of next_id or prev_id fail:
var prev_id = $(this).data(prev_id);
just returns [object Object]
var prev_id = $(this).data("prev_id");
or
var prev_id = $(this).data('prev_id');
Returns Undefined
I think I'm missing something fairly obvious - really grateful for any pointers