$('#search').keypress(function(e) { if(e.which == 13) { $("#form").fadeOut(function() { $("#loading").fadeIn(); }); // The rest of the code will go here. } });