You should look into jQuery 1.4, the new API has made it so easy to create new DOM and the code is still human readable
Here is an simple example of creating a new dynamic row and add it to the table. Inside the row, there are several form elements with the events attached to them.
jQuery("<tr />")
.append(
jQuery("<td />", {
text: name
})
)
.append(
jQuery("<td />", {
html: jQuery("<input />", {
"type": "text",
"name": "rule[properties][" + name + "]",
val: value
})
})
)
.append(
jQuery("<td />", {
html: jQuery("<input />", {
"type": "checkbox",
"name": "rule[important][" + name + "]",
"checked": isImportant
})
})
)
.append(
jQuery("<td />", {
"style": "text-align: right;",
html: jQuery("<img />", {
"src": "/buttons/pane_button_remove.png",
click: function() { jQuery(this).closest("tr").remove(); }
})
})
)
.appendTo("table");
more info here