I have a function which i used to add elements to a list, I want to have events run on interaction with this list, e.g. click. If I do it using the document object it works well however if I use jQuery with underscore templates the element is successfully appended but the events will not trigger.
var addElement = function(parentElement){
//would work
this.thisElement = document.createElement('li');
parentElement.appendChild(thisElement);
$(this.thisElement).click(function(event){
alert('working');
});
//doensn't work
this.template = _.template($('#fileListEntity').html());
var li = this.template();
$(parentElement).append(li);
$(li).click(function(e) {
alert('notWorking');
});
};
so with the help of megakorre this is the answer.