- var myDiv = new Element('div' { 'tabindex': '0' })
- myDiv.observe('keypress', function(e) {
- var code;
- if (!e) var e = window.event;
- if (e.keyCode) code = e.keyCode;
- else if (e.which) code = e.which;
- alert(String.fromCharCode(code));
- });
Showing posts with label Prototype. Show all posts
Showing posts with label Prototype. Show all posts
2.11.2009
Attaching keyboard events to alternative browser objects
It took me way too long to find out why I could not listen to keyboard events for DOM objects other than the window, form objects, or links. All you have to do is give the div or any other DOM element a tabindex. Below is an example using the prototype framework.
Labels:
GUI,
Javascript,
Prototype
Subscribe to:
Posts (Atom)