I just can't get this to work. It works fine in the console of Google Chrome. I added $(document).ready(function ()
. Still no luck. Any help is greatly appreciated. update: I'm trying to get the value of the first cell when the row is selected on a dynamically created html table
Script
<script type="text/javascript">
$.ajax({
url: '@Url.Action("VisitList")',
method: 'post',
dataType: "json",
contentType: 'application/json;charset=utf-8',
data: "{id: 112601}",
success: function (data) {
//alert("success");
$('#divData').removeClass('hidden');
$('#tblBody').empty();
$.each(data, function (index, value) {
var row = $('<tr><td>' + value.JobID + '</td><td>'
+ value.VisitID + '</td><td>'
+ value.VisitDate + '</td><td>'
+ value.VisitInfo + '</td><td>'
+ value.Engineer + '</td></tr>');
$('#tblData').append(row);
});
},
error: function (xhr) {
alert(xhr.responseText);
}
});
$(document).ready(function () {
$("#tblBody tr").click(function (rowElement) {
//alert("hello");
var value = $(this).find('td:first').html();
alert(value);
})
});
</script>