Detect Enter key is pressed with jquery

<input type="text" id="txt"/>

$('#txt').keydown(function (e){
    if(e.keyCode == 13){
        alert('you pressed enter ^_^');
    }
})

On jsfiddle.


Use this, it works for me :)

$("#search-txt" ).on( "keydown", function(event) {
    if(event.which == 13) 
        return false;//do something
});