I have a button on my page, and on click it displays a dynamically created table. This is happening in a JS file. Part of the table creation is as follows-
table_body = '<table border="1">';
table_body += '<tr>';
table_body += '<th>';
table_body += '';
table_body += '</th>';
table_body += '<th>';
table_body += 'Name';
table_body += '</th>';
table_body += '<th>';
table_body += 'Age';
table_body += '</th>';
table_body += '</tr>';
for(var i=0;i<number_of_rows;i++){
table_body+='<tr>';
table_body += '<td>';
table_body += i+1;
table_body += '</td>';
table_body += '<td>';
table_body += name[i];
table_body += '</td>';
table_body += '<td>';
table_body += '<a href="" id='+name[i]+'>Age Action</a>';
table_body += '</td>';
table_body+='</tr>';
}
table_body+='</table>';
document.getElementById("tableDiv").innerHTML = table_body;
I am using Joomla Seblod and I have a div called tableDiv, and I'm replacing that div on the page with my created table after button click. I'm not able to track clicks (and then do other stuff) on Age Action above, from the same JS file. On the same file I have-
jQuery("#55").click(newTestFunction); //I have a console.log in newTestFunction
id=55 in the first Age Action row. Is it because it's being dynamically generated? I have added the id attribute that should be different for different rows of it, but when I click on any one of them, it's not logging the console message that I have on click.
I also checked the page source and it does not show any of the elements of the table. How/where can I track any click on the element? Any help will be appreciated.