I add a click event handler to an element
$(\".elem\").click(function(){ $.post(\"page.php\".function(){ //code1 }) })
Wrap code2 in method and add it as a callback inside code1 so it will always get called after code1 executes
code2
code1
code2 = function(){/*code2*/}; $(".elem").click(function(){ //code1 code2(); })