I'm putting together a "FAQ" type of page, and my code isn't working for what seems like no reason. Basically, whenever I try to refer to anything's ID outside of the .getJSON call, it doesn't work. My click event on paragraphs is even refusing to fire (the alert doesn't pop up). What am I doing wrong!
$(document).ready(function () {
$.getJSON("samp.json", function(result) {
for(i=0;i<result.length;i++){
var textField = $('<p />').appendTo('body');
qaDiv = $('<div />').appendTo('body');
textField.attr("id", result[i].categoryTitle);
textField.text(result[i].categoryTitle);
qaDiv.attr('id', result[i].categoryTitle + "qa");
for(i2=0;i2<result[i].qaArray.length;i2++){
var qa = $('<p />').appendTo(qaDiv);
qa.html(result[i].qaArray[i2].question + "</br>" + result[i].qaArray[i2].answer);
}
}
});
$("p").click(function () {
alert("sfsd");
$("#Moviesqa").slideUp();
});
});