I have successfully hooked the EnterKey event at the document level as following:
$(document).keypress(function (e) {
if (e.which == 13) {
alert('You pressed enter!');
}
});
But, I am unable to hook the EnterKey event on a Div with id "myDiv".
<div id="myDiv"></div>
$("#myDiv").keypress(function (e) {
if (e.which == 13) {
alert('You pressed enter!');
}
});
Is it possible to detect an EnterKey press within a Div? Actually, the Div contains some input/select controls which are used to filter the content of a Grid. I want to hook the EnterKey event so that when the EnterKey is pressed I can filter the Grid.
EDIT: Please note that I have inputs within the div(I've intentionally not shown them here). I don't want to hook the event manually for each of the input control within the Div. Also, I am assuming that when user presses EnterKey at least one input control shall have focus.