Trying to figure this out, and I think I know the problem, but I don't know how to fix it. When my page loads first, I use a JSON file to provide some links on the page, using $ .getJSON to create them and give them identifiers, dynamically. My code for this (this is just what interests me, I, of course, close the function):
$(function() { $.getJSON("data.json", function(data) { var navOutput = ""; for (var key in data.navigation) { navOutput += '<li><a id="' + key + '">' + data.navigation[key] + '</a></li>';
Everything loads fine on the page. Outside of the $ .getJSON function, I am trying to assign an event listener to one of these dynamically created identifiers as an example:
$("#cast").click(function() { alert("Testing"); });
This does not work. There is probably a simple answer to this question, but I cannot figure it out. If I assign an event handler to an identifier on a page created in HTML, it works, so it has something to do with these dynamic identifiers. Any help would be appreciated.
source share