At first I made a simple array just inside the .js file and wrote the function to make list items from it. Then clicking on freshly created li elements should do something.
//This code works
dic[0] = "decir";
dic[1] = "querer";
dic[2] = "poder";
$(document).ready(
function verbsarray() {
for (var i = 0; i < dic.length; i++) {
var verbo = dic[i];
verbos += "<li class='h_li'>" + verbo + "</li>\n";
};
$('ul.h_list').html(verbos);
});
$(".h_li").click(function() {
alert("it works!");
//Dollar finds .h_li here
}
Since that was a prototype, then I developed that function to take items not from the static array, but from loaded JSON. Function parses the needed items and again makes list items from them.
But the other function (that looks for clicked <li class="h_li">
) now doesn't work...
//this doesnt work :-(
function verbos_from_json () {
$.getJSON('verbos.json', function verbsarray(vjson) {
for (var i = 0; i < vjson.data.length; i++) {
verbo = vjson.data[i].verb;
verbos += "<li class='h_li'>" + verbo + "</li>\n";
};
$('ul.h_list').html(verbos);
});
};
$(".h_li").click(function() {
alert("it works?.. no");
}