javascript - Can you bind an event to access keys? -


as know, in html there's accesskey attribute lets assign key elements can trigger/focus them directly keyboard, without having tab them first.

now wondering, if can bind js event exact... event, or have go old-fashioned way , listen onkeypress (for example) , check key combination?

the latter kind of defeat purpose, since browsers have different key combinations trigger access keys.

my idea behind assigning access key (mega menu) navigation, unfold , focus it, can tab through links. way can put navigation @ end of html, users don't have tab through hundreds of links (exaggeration) before can reach links in actual content area.

there no such event, instance no onaccesskey event have hook 1 of onkey* events.

however accesskey trigger activation events elements when accesskey used (tested chrome , firefox). can use events if user clicked,focused,changed part of ui.

  1. display elements, i.e. div,span, etc:
    • onclick
  2. input elements, i.e. text,textarea:
    • onfocus, if not focused
    • onclick in browsers
  3. input elements, i.e. radio,checkbox:
    • onfocus, if not focused
    • onclick
    • onchange, if not checked
  4. select elements:
    • onfocus, if not focused
    • onclick, if not selected
  5. select element options (triggered on select element):
    • onfocus, if select box not focused
    • onclick, if select box not selected
    • onchange, if option not selected

jsfiddle demo

an example of using open menu

html

<div id="menu">     <div id="menubtn" accesskey="r">menu</div>     <ul>         <li>item 1</li>         <li>item 2</li>         <li>item 3</li>     </ul>     </div> 

js

jquery("#menubtn").click(function(){    jquery(this).next().toggle();  }); 

jsfiddle demo


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -