Click events for the child nodes the parent are not fired when html is append to the div but event is fired when content is static on document.ready
. Is there something im doing wrong here?
$(document).ready(function(e) {
runAPISearch(); //Make httpRquest to movieDBAPi
$('.card').click(function(e) {
console.log("remove div"); //CLICK EVENT NOT FIRED
});
$('.cardImg').click(function(e) {
console.log("clicked Img"); //not fired either.
});
});
functions
function parseData(data){
var i=0;
for (i = 0; i < data.length; i++){
var template = $("#template").html();
var prependTemplate = template.replace("{{cardId}}", i).replace("{{imgSrc}}", poster_path);
console.log(prependTemplate);
$(".container").prepend(prependTemplate);
}
}//ParseData ends
HTML TEMPLATE
<script type="text/template" id="template">
<div id="{{cardId}}" class="card">
<img class="cardImg" src="{{imgSrc}}">
</div>
</script>
<div class="container">