There is a table that is partially created
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <table class="table table-striped table-bordered table-hover" id="table"> <tr> <td><b>#</b></td> <td><b>Фамилия</b></td> <td><b>Имя</b></td> <td><b>Отчество</b></td> </tr> </table> And there is javascript
<script type="text/javascript"> $(document).ready(function () { $.ajax({ type: "POST", url: "DataTable", contentType: 'application/json; charset=utf-8', dataType: 'json', success: function (data, textStatus, jqXHR) { $.each(data, function (i) { $("#table").append("<tr id = '" + (i+1) + "'> <td>" + (i + 1) + "</td> <td>" + data[i].Surname + "</td> <td>" + data[i].Name + "</td> <td>" + data[i].Lastname + "</td> </tr>"); i++; }); } }); $('table tr').bind('click', function () { alert("dsfsdf111111"); }); }); $('table tr').bind('click', function () { alert("dsfsdf111111"); }); $("#4").on("click", function () { alert("dsfsdf"); }); </script> When I click on the created append lines, nothing happens, and when I click on the line that was originally created by the html code, the alert function is called. How to make the event handler trigger when clicking on the created lines?
And how can I specify that when I click on the identifier from 1 to .... the onclick handler is called?