I'm adding a button dynamically by doing:
<input id="{Id}" type="submit" value="View">
{Id}
is replaced at runtime with the record id.
I would like to have a function like:
function viewRecord(button) {
//Do something here...
}
How can I add a click listener to the button that corresponds to the correct button being clicked?
I've started learning jquery
today and would like an answer that shows how it's implemented.
EDIT
Based on the answer below, I'm trying the following:
<td><input class="viewRecord" type="submit" value="View"></td>
$(".viewRecord").click(function () {
var $table = $('#table'),
var $tableBody = $table.find('tbody'),
var $text = $tableBody.closest('tr').attr('id');
alert($text);
});
However, no alert is being displayed.
Am I missing something?