SoFunction
Updated on 2025-04-07

Event implementation code in dynamically created table cells

The code is as follows
var tableElem = ("MyTable");
var tbodyElem = ("tbody")[0];
var trElem = ("tr");
var td1 = ("td");
= "EditCell()";

= "45%";
= " ";
(td1);
(trElem);
alert();

This code dynamically creates a tr and td, and sets an onclick event in td, but the fact is that when td is clicked, the EditCell function is not set off to call the click time. Then = "EditCell()"; changed to ("onclick", EditCell) before successfully calling