Reputation: 1299
$("#id").keydown(function(evt) {
alert('Hello');
});
I tried this, but this is not working, Can you correct this ?
Upvotes: 2
Views: 18068
Reputation: 1
You should use jquery.keydown
in $(document).ready
. Also make sure that you've unique id
of the div
.
HTML:
<input id="yourId" type="text">
JS:
$(document).ready(function () {
$("#yourId").keydown(function(evt) {
alert('Hello');
});
});
Upvotes: 0
Reputation: 1162
Your code is correct. I think you must make sure you included jquery. And also make sure your text element has the same Id as used in your jquery code.
In this case make sure the input type is the following.
<input type="text" id="id" />
Also press F12 and look in the console what error is occurring.
Upvotes: 0
Reputation: 14381
It works: http://jsfiddle.net/rrikesh/v7MdG/
HTML:
<input type="text" id="id">
JS:
$("#id").keydown(function(evt) {
alert('Hello');
});
Upvotes: 3