I am calling a function named edit from an onclick event as follows.
<script type="text/javascript">
$(document).ready(function () {
...
$.each(data, function (key, val) {
...
var td11 = $('<input type="button" value="Edit" onclick="edit();" />')
.attr("name",val.Id);
$(tr2).append(td11);
$(table1).append(tr2);
});
$("#cers").append(table1);
The function is defined outside the $.each loop, inside $(document).ready, as follows
function edit() {
alert("Id ");
}
When i click on Edit button, Chrome shown error : Uncaught ReferenceError: edit is not defined.
No other errors.
Probably you have defined
editfunction not in global scope. It should be defined outside not only$.eachloop, but outside$(document).readyand etc. For example this works:But it is better to bind event in javascript, in your case: