I am currently trying to figure out why the click() does not work on the buttons that have been dynamically created with js. Below is the code I have:
jQuery(document).ready(function()
{
jQuery.ajax({
url:ajaxobject.ajaxurl,
method: 'GET',
data: {
action: '2017_application'
},
success: function(data)
{
var applications = JSON.parse(data);
for (var i = 0; i < applications.length; i++)
{
var content = '<div class = "app2-row app2-data">' +
'<div class = "app2-col" style="font-weight:bold;">' + applications[i]['teamname'] + '</div>'+
'<div class = "app2-col">' + applications[i]['firstname'] + '</div>'+
'<div class = "app2-col">' + applications[i]['lastname'] + '</div>'+
'<div class = "app2-col"style="font-weight:bold;">' + applications[i]['status'] + '</div>'+
'<div class = "app2-col">' +
'<button onclick="window.location.href=\'/info/?teamname='+ applications[i]['teamname'] + '\'">View</button><br>' +
'<button class = "app2-accept" tname='+applications[i]['teamname']+'>Accept</button><br>' +
'<button class = "app2-remove">Remove</button><br>' +
'</div>'+
'</div>';
jQuery("#app2-table").append(content);
}
}
});
When I use click() on the ".app2-accept" nothing happens.
jQuery(".app2-accept").click(function()
alert("Testing");
});
Can anyone advise how to resolve this?