I need to make certain "appended" html content "clickable". Here is the code:
function displayContacts(contactArray){
var jsonObject = $.parseJSON(contactArray);
jsonObject.forEach(function (dat) {
//Begin Contact Unit
$('.feed')
.append('<div class="feed-img"><img src="'+dat.avatarUrl+'">\
</div><div class="feed-text"><p><span class="name_highlight">\
' + dat.firstName + ' ' + dat.lastName + '</span></p></div>');
//End Contact Unit
});
}
I have a AJAX call not shown that gets 3 pieces of data in JSON. This function then appends that data to an html doc in order to create a list of contacts - in this case it's a master list of every user in the db. My question is: how would I go about making these elements (the images, for example) clickable? The goal is to make this list of contacts in such a way that the user can select one by clicking on the avatar. I have tried using .on
, .click
, many different things and I think it may require one of those but I am not sure where to place it in the actual code. The way I understand it is these elements are dynamically created, which makes them special. Thank you for any help - this has really confused me.