I have a modal in Bootstrap 4 with multi tabs each formatted with tables. Data is added to the table from an ajax call and is not there at startup. I want to click a and highlight the with a background-color, but cannot get the code to fire. Extracted snippets of code are as follows:
<head>
<style
td.highlight {
background-color:yellow;
}
</style>
</head>
<body>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#getDetails">
Open modal
</button>
<!-- MODAL-->
<div class="modal fade" id="getDetails" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog roundbox shadow" role="document">
<div class="modal-content" style="background-color:white;font-size:.85rem;">
<div class="card" id="card2">
<table width="100%">
<tbody id="children">
<tr height="24"><td>Children:</td><td>(none)</td></tr>
<tbody>
</table>
</div>
<div style="margin:10px;">
<button type="button" class="btn btn-sm btn-danger" style="float:left;" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-sm btn-success" style="float:right;" onclick="saveDetails();">Submit</button>
</div>
</div>
</div>
</div>
<script>
$(function(){
var code = '<tr height="24"><td>Children:</td><td class="kids" id="child0" data-id="2" data-gender="1"><span class="bname">SURNAME</span> John Ainsworth b.1945</td></tr>' + "\n"
+ '<tr height="24"><td></td><td class="kids" id="child1" data-id="1" data-gender="1"><span class="bname">SURNAME</span> David Neale b.1946</td></tr>' + "\n"
+ '<tr height="24"><td></td><td class="kids" id="child2" data-id="11" data-gender="1"><span class="bname">SURNAME</span> Phillip Robert b.1950</td></tr>' + "\n"
+ '<tr height="24"><td></td><td class="kids" id="child3" data-id="28" data-gender="0"><span class="bname">SURNAME</span> Margaret Lesley b.1951</td></tr>' + "\n";
$('#getDetails table tbody#children').html(code);
});
// TOGGLE HIGHLIGHT
$('td.kids').on("click", function(e) {
if ($(this).hasClass("highlight")) {
$(this).removeClass("highlight");
} else {
$(this).addClass("highlight");
}
});
</script>
</body>
The "highlight" code is not firing. I have looked through previous answers to similar problems and tried everything suggested, but cannot get it to work.
Any suggestions?