$("#searchstring").keypress(function(e) { if (e.which == 13) { window.location.href=$(this).find("a").attr("href"); return false; }; });