Skip to Content (Press Enter)

This document is a draft, and is designed to show changes from a previous version. It is presently showing added text,changed text,deleted text,[start]/[end] markers,and Issue Numbers.

Hide All Edits   |   Toggle Deletions  |   Toggle Issue Numbers   |   Toggle [start]/[end] Markers   |   Show All Edits

Changes are displayed as follows:

F42: Failure of SC 1.3.1 and 2.1.1 due to using scripting events to emulate links


HTML 4.01 and XHTML 1.x with Scripting.

This failure relates to:


This failure occurs when JavaScript event handlers are attached to elements to ''emulate links''. [begin add]A control or link created in this manner cannot be tabbed to from the keyboard and does not gain keyboard focus like other controls and/or links. [1993] [end add]If scripting events are used to emulate links, user agents including assistive technology may not be able to identify the links in the content as links. They may not be recognized as interactive controls by assistive technology, or they may be recognized as interactive controls but still not recognized as links. Such elements do not appear in the links list generated by user agents or assistive technology.

The <a href> and <area> elements are intended to mark up links.

Attaching event handlers to elements that are not normally interactive, such as span and div, can be quite disorienting to users. Even if care is taken to provide keyboard access to such elements, users may have a difficult time discovering that there are interactive controls in the content or understanding what type of behavior to expect from them. For example, users may not know which keystrokes are supported by the script to activate the element. Additionally, these elements do not generate the same operating system events as interactive elements, so assistive technology may not be notified when the user activates them.


Failure Example 1: Scripting a <span> element

Scripted event handling is added to a span element so that it functions as a link when clicked with a mouse. Assistive technology does not recognize this element as a link.

<span onclick="this.location.href='newpage.html'">
    Fake link

Failure Example 2: Scripting an <img> element

Scripted event handling is added to an img element so that it functions as a link when clicked with a mouse. Assistive technology does not recognize this element as a link.

   alt="go to the new page" 

Failure Example 3: Scripting an <img> element, with keyboard support

Scripted event handling is added to an img element so that it functions as a link. In this example, the link functionality can be invoked with the mouse or via the Enter key if the user agent includes the element in the tab chain. Nevertheless, the element will not be recognized as a link.

function doNav(url)
   window.location.href = url;

function doKeyPress(url)
   //if the enter key was pressed
   if (window.event.type == "keypress" &&
       window.event.keyCode == 13)

The markup for the image is:

	<img src="bargain.jpg"
		alt="View Bargains"

Failure Example 4: Scripting a <div> element

This example uses script to make a div element behave like a link. Although the author has provided complete keyboard access and separated the event handlers from the markup to enable repurposing of the content, the div element will not be recognized as a link by assistive technology.

window.onload = init;

function init()
	var objAnchor = document.getElementById('linklike');

	objAnchor.onclick = function(event){return changeLocation(event,
	objAnchor.onkeypress = function(event){return changeLocation(event,

function changeLocation(objEvent, strLocation)
	var iKeyCode;

	if (objEvent && objEvent.type == 'keypress')
		if (objEvent.keyCode)
			iKeyCode = objEvent.keyCode;
		else if (objEvent.which)
			iKeyCode = objEvent.which;

		if (iKeyCode != 13 && iKeyCode != 32)
			return true;

	window.location.href = strLocation;

The markup for the div element is:

<div id="linklike">
View the results of the survey.


No resources available for this technique.



  1. Check whether there are JavaScript event handlers on an element that emulates a link.

  2. Check whether the programmatically determined role of the element is link.

Expected Results