Why does this work:
$(window).keydown(function(event){
alert(event.keyCode);
});
but not this:
$('#ajaxSearchText').keydown(function(event){
alert(event.keyCode);
});
I'm testing with Firefox 3. Interestingly, neither of them work in IE7.
Checked this in Chrome, IE7 and Firefox 3.0.3. Works as it should. jQuery version 1.2.6.
<html>
<head>
<script type="text/javascript" src="jquery-1.2.6.js"></script>
<script type="text/javascript">
$(function()
{
$("#ajaxSearchText").keydown(function(event)
{
alert(event.keyCode);
});
});
</script>
</head>
<body>
<input type="text" id="ajaxSearchText"></input>
</body>
</html>
To fix the issues in IE6 and IE7, try this...
$(function()
{
$(document).keydown(function(event){
alert(event.keyCode);
});
});
Attaching the event to the $(document) seems to be the magic things here.
Your first bit of code really should work in IE as well though. It seems to be down to a bug in jQuery that will hopefully be fixed soon...
Here is a link to the bug report in jQuery. https://bugs.jquery.com/ticket/3614
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With