Reputation: 5193
Alright, so I'm trying to make a simple script that moves down a div when I press 's' but it's not firing at all. I got Jquery installed, and the error-console in FF isn't saying anything. Can someone tell me what I'm doing wrong?
http://prime.programming-designs.com/designs/map/
Upvotes: 1
Views: 484
Reputation: 50177
Here's your code:
$('#map').keydown(function(event) {
switch (event.keycode) {
case 83: // left arrow key
markX = markX + markSpeed;
mark.style.top = markX + 'px';
break;
}
});
The issues are that keycode
needs to be camelCase keyCode
and that the case
should be 37
for the left arrow or 40
for the down arrow.
Upvotes: 1
Reputation: 179046
You forgot to put //
before your HTML open comment tag <!--
You shouldn't use HTML comment tags for scripts anyway, the best method for inline styles/scripts is to use the CDATA
element as follows:
/* <![CDATA[ */
//your code in here
/* ]]> */
This does a number of things:
Upvotes: 1
Reputation: 47749
I suggest you use the jquery.hotkeys extension to bind to the key events: https://github.com/jeresig/jquery.hotkeys
Upvotes: 1