var id = $(this).children().html(); // id is 5 $.ajax({ url: \'ajax.php?id=\' + id, success: function(data) { id = data; // id is 1 } }); if(id == 1){
The A in Ajax is for Asynchronous. From within the 'success' callback you can call another function or execute post-ajax code.