I am using ie 11. I am adding a row to a table. I am using a modal popup to enter the data and I am making an AJAX call to update the underlying data. When that is done, I am using JQuery to add the row to the table. This all works fine except for one thing. The end of the tablerow contains a button. All the other buttons on the table work, but the new button does not. When I look in developer tools the button for the new row has the same mark up as the mark up for the others, so it should work in the same way. So the table looks this;
<table class="GridTbl" id="surveyList">
<thead>
<tr>
<th>Survey</th>
<th>Contract</th>
<th>Select</th>
</tr>
</thead>
<tbody>
@foreach (var contract in
SessionObjectsMSurvey.ContractList.Where(x => x.SurveyId > 0)
.OrderByDescending(x => x.SurveyCreated))
{
<tr>
<td>@contract.SurveyTitle</td>
<td>@contract.ContractTitle</td>
<td>
<button class="btn btn-xs btn-primary selectContract"
data-msurvey-row-id="@contract.RowId">
Select
</button>
</td>
</tr>
}
</tbody>
</table>
I add the row of data here. Notice the button has a class of selectContract. This works
var addRowToTable = function (data) {
var row =
'<tr>' +
'<td>{{surveyTitle}}</td>' +
'<td>{{contractTitle}}</td>' +
'<td>' +
'<button class="btn btn-xs btn-primary selectContract" data-msurvey-row-id="{{rowId}}">Select</button>' +
'</td>' +
'</tr>';
//Add row
$('#surveyList').prepend(row.compose({
'surveyTitle': data.SurveyTitle,
'contractTitle': data.ContractTitle,
'rowId': data.RowId
}));
};
And this is the click event which usually works but not for the new row. The button on the new row does fire an event, I do not know where the event handler is, it should be this one but it isn't;
$(".selectContract").on("click", function (e) {
e.preventDefault();
var $this = $(this);
var rowId = $this.data("msurvey-row-id");
var url = GetHiddenField("msurvey-get-contract-and-survey-url");
dataService.getContractAndSurvey(rowId, displayContractInfo, url);
});