I'm using jquery to append HTML to an ID; specifically, I am having trouble placing a JSON-formatted string into the onclick parameter of an element. I intentionally want the JSON to be parsed onClick and am perfectly okay with the JSON living in the DOM for this specific effort.
I think the problem is related to escaping the quotes properly (because a Chrome Inspect Elements debug reveals that each JSON element is being treated as an HTML tag as opposed to a string--see https://ibb.co/eHOgq8 for screenshot of how the DOM is being interpreted)
var str = '{"artist":"So and So","title":"Not Relevant"}';
$("#d").append('<ul><li><a onclick="JSON.parse(\'' + str + '\')" title="NA">Link</a></li></ul>')
I've tried using numerous escaping mechanism and quote types as well as some native Javascript escaping and gotten no where. After 2 hours, I have to turn SO for help. Thank you so much in advance.