I have the following code:
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$.getJSON('livros.json', function(data) {
$.each(data, function(i, item) {
console.log(item.name);
$("#lista").append("<li><a class='livro'>" + item.name + "</a></li>");
});
});
</script>
<script type="text/javascript" src="js/script.js"></script>
<body>
<div id="wrapper">
<ul id="lista">
</ul>
</div>
</body>
The above code is listing my json and settling with append
in html, until everything is working, but now I want to get the click action on each a
tag in the html.
and I'm not getting it.
Click script that is not working:
$(document).on('click', '.livro', function() {
console.log("foi");
});