I have an AJAX call when the user enters the parameters, which the MySQL database returns a row, and shows it to the user through a table. I want to have it so that when they click a row, it calls back for the MySQL database, using a unique hash, to get the contents of the row that they clicked and show it in a div. So for instance, if there's a table like
JOHN | 21 | foo.com
AMY | 29 | bar.com
that the MySQL database returned, the user can click on the row John | 21 | foo.com
and get something like
John have been working at foo.com for 22 years...
on the div below the table. I've been able to work out most of it, but having the row be clickable is a bit of a challenge. Since I have Jquery, if I do something like
$('.dashboard_main_row').click(function(){
alert('This is an alert');
});
It doesn't work, as I assume the AJAX call is made after the page has been loaded, although it does on something like a static webpage in jsfiddle. So I have two questions:
How would I implement this in JQuery where the rows are getting re-generated every time the user desires?
How can I have a row be identifiable so that if they click
john
I get the contents ofjohn
notamy
? (I do have a column hidden by CSS where it does show unique hashes.)
EDIT: I did try the method that the one the mod linked as "duplicate":
$('.dashboard_main_row').on('click', 'tr', function(){
alert('This is an alert');
});
And it doesn't work. That's why I switched to .click()
instead.
Just for conciseness, here's my html code:
<table>
<tbody id = "dashboard_tbody">
<tr class = "dashboard_main_row">
<td> John </td>
/* ... */
</tr>
</tbody>
<table>