CHASE CHASE - 1 year ago 93
Javascript Question

JS (Jquery) .keydown event that triggers an alert

Hey everyone I am trying to figure out how to make the jquery keydown event on the entire page. In this code instance if a person presses "q" then an alert pops up saying "anything here.". But my issue is that the js I wrote seems to no work properly. Thank you.

<script src="//"></script>
<script src="//"></script>
<script type="text/javascript">
$(window).keydown(function () {
if (event.which == 81) {

Answer Source

Don't forget to pass the event into your function :)

$(window).keydown(function (event) {

Also, as pointed out by @praveen in the comments to OP, script order should be swapped so jquery is included before the jquery-ui script.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download