How do I get the value of each key pressed and use it in a variable with jQuery? I want to press a key and show a specific picture on a page that correlates with that key when it is pressed. I also ONLY want to target AZ and "."
Thank!
Using jQuery, you can use the event keypressand then convert the character to a string and match it with your criteria.
keypress
Here's a working example :
$(document).keypress(function(e) { var s = String.fromCharCode(e.which); if (s.match(/[a-zA-Z\.]/)) console.log(s + ' is a match!'); });
:. $('#LearnStart'), .
$('#LearnStart')
heres jquery Keypress
ids, #. id LearnStar script :
$("#LearnStar").live("keypress",function(e) { var s = String.fromCharCode(e.which); if (s.match(/[a-zA-Z\.]/)) console.log(s + ' is a match!'); });
, script.
, , , e.preventDefault() false .
e.preventDefault()