views:

709

answers:

4

So, I'm testing all different HTML tags and attributes, freshing things up a bit, and for some reason, accesskey does not appear to be working.

The accesskey attribute is used to assign a key to an element. Depending on your OS, pressing Alt+that key (Windows) or Cmd+that key (Mac) will give focus to that element.

Here's a little something:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us">
<head>
    <title>Title</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style type="text/css">
        a:focus{
            color:red
        }
    </style>
</head>
<body>
    <a accesskey="x" target="new" href="#">Hello</a>
</body>
</html>

So I'm working on a Windows machine. Thusly, I expect the anchor to go red when I press Alt+x. Yet it is not. Is there something wrong with the code, or am I expecting the wrong thing to happen?

On Firefox, nothing happens. Google chrome opens a new tab (as it should, the target attribute say "new", which means open in new tab/window) and IE jumps to the anchor but does nothing further.

+3  A: 

Firefox's accesskey modifier is Shift+Alt.

bobince
are you sure? In the example posted by the topicstarter, a new tab is opened when I hit Shift+Alt+x
Natrium
Thanks. Firefox both goes to the anchor and open the new tab, a combination of what Chrome and firefox do.Also, here's something else I noticed: try commenting on your posts here. Type a few words and then press Shift+Alt+xYour text-alignement will shift to "right" instead of "left"
Vordreller
And the Firefox modifier on the Mac is just Ctrl.
Alessandro Vernet
+1  A: 

You have to press Enter to follow the link when it has the focus in IE.

John Topley
A: 

In firefox you need to press shift+alt. In IE hitting the modifyer key only sets focus to that element, this is by design. These are the only two browsers accessible with my screen reader so can't give you more info on others.

Jared
+1  A: 

If you're determined to assign accesskeys (and there may be some good reasons to use this terribly implemented feature), you should take a look at WebAIM's page on accesskeys which outlines some of the obstacles you'll face.

One thing, on the Mac most browsers that support accesskeys --except Opera-- use Control not Command. Opera apparently uses Shift-Esc ... who knew?