The real thing I am trying to do is understand why my dynamic linked object does not say hello when clicked (see bottom of code). But it may be because I have a preceding error--when I run this, the first test alert (in the loop) tells me the key is "error". In the console it says the parse has a syntax error on '<'...but there isn't any such char in the JSON. It is not even real ajax, just a demo:
$(document).ready(function () {
//main ajax call to populate the menu
$.ajax({
dataType: 'json',
url: 'https://jsfiddle.net/afk4cpz4/',
success: function (data) {
$.each(data, function(key) {
alert("The key is: "+ key);
var myname = data[key].name;
$("#epresults").append("<div class='inner"+[key]+" namer'>"+myname+"</a></div>");
$(".inner" + [key] + "").wrapAll("<div id='item" + [key] + "' class='tile ditem" + [key] + "' />"); //build the tile
$("div#item" + [key]).wrap("<a class= 'ditem" + [key] + "' href='#' />"); //wrap the tile in a link
});
},
error: function (xhr, desc, err) {
console.log(xhr);
console.log("Details: " + desc + "\nError:" + err);
}
});
$("#epresults").show();
$(" a ").click(function () {
alert("Hello");
});
});
https://jsfiddle.net/jhxqkg1q/21/
What's wrong?