Events do not fire after dynamic HTML change
Some stage setting: I have a table, and some of the columns in the table have a class (removed some columns for brevity):
- <table id="OrderDetails" width="100%" cellpadding="0" cellspacing="0" class="listtable">
- <tr>
- <td class="pagejump" id="row_0" align="center"><img src="JumpBullet.png"/></td>
- <td class="title">title for row 0</td>
- </tr>
- </table>
In my document.ready, I have a hover event handler that works fine. I also have a click event handler. Again, all works great when the page first loads.
- $(function() {
- $(".pagejump").click(function() {
- var fldID = $(this).attr("id");
- var curID = fldID.slice(4);
- // send this info back to the server
- });
- $(".pagejump").hover(function() {
- $(this).addClass("hoverBkg");
- },
- function() {
- $(this).removeClass("hoverBkg");
- });
- });
The problem comes if I replace the rows in the table with new rows (that still have the same classes assigned to the same columns):
- function ReloadOrders(strOrders) {
- $("#OrderDetails").html(strOrders);
- }
My table still looks fine, everything is in place (the actual code has about 8 columns), but now none of the events fire. So, somewhere in the document.ready, jquery must be hooking up the elements with the event handlers, and that isn't happening after I replace. Pointers to docs are welcome.
Thanks,
Greg