Try replacing the click handler with a delegated handler attached to the parent of the table.
$("#report").delegate("tr.odd", "click", function() { $(this).next("tr").toggle(); $(this).find(".arrow").toggleClass("up"); });
Since the click event is captured by the table, clicking on new (replaced) elements will work as expected, since the event bubbles from the target element to the parent to which the handler is attached. The handler will execute the passed function only if the element captured by the selector, passed as the first parameter in .delegate , matches the target element.
EDIT: jQuery 1.3.2 does not have .delegate , but you can use .live :
$("#report tr.odd").live("click", function() { $(this).next("tr").toggle(); $(this).find(".arrow").toggleClass("up"); });
To reapply your CSS, you can do this:
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { document.getElementById("myDiv").innerHTML = xmlhttp.responseText; $("#report tr:odd").addClass("odd"); $("#report tr:not(.odd)").hide(); $("#report tr:first-child").show(); }
or get rid of this long ajax method and use $.load as suggested by @Tieson T:
$("#changeContent").click"(function() { $("#myDiv").load("getData.php", function() { $("#report tr:odd").addClass("odd"); $("#report tr:not(.odd)").hide(); $("#report tr:first-child").show(); }); });
and don't forget to change your button to use with the above solution.
<button type="button" id="changeContent">Change Content</button>
source share