See Understanding Techniques for WCAG Success Criteria for important information about the usage of these informative techniques and how they relate to the normative WCAG 2.0 success criteria. The Applicability section explains the scope of the technique, and the presence of techniques for a specific technology does not imply that the technology can be used in all situations to create content that meets WCAG 2.0.
HTML and XHTML
This failure relates to:
This failure occurs when JavaScript event handlers are attached to elements to emulate links. A link created in this manner cannot be tabbed to from the keyboard and does not gain keyboard focus like other controls and/or links. 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 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.
role
attribute to identify an anonymous element as link control for assistive technologies. However, best practice for ARIA calls for making use of native elements whenever possible, so the use of the role
attribute to identify anonymous elements as links is not recommended.The a
and area
elements are intended to mark up links.
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.
Example Code:
<span onclick="location.href='newpage.html'">
Fake link
</span>
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.
Example Code:
<img src="go.gif"
alt="go to the new page"
onclick="location.href='newpage.html'">
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.
Example Code:
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)
{
doNav(url);
}
}
The markup for the image is:
Example Code:
<p>
<img src="bargain.jpg"
tabindex="0"
alt="View Bargains"
onclick="doNav('viewbargains.html');"
onkeypress="doKeyPress('viewbargains.html');">
</p>
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.
Example Code:
window.onload = init;
function init()
{
var objAnchor = document.getElementById('linklike');
objAnchor.onclick = function(event){return changeLocation(event,
'surveyresults.html');};
objAnchor.onkeypress = function(event){return changeLocation(event,
'surveyresults.html');};
}
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:
Example Code:
<div id="linklike">
View the results of the survey.
</div>
Resources are for information purposes only, no endorsement implied.
For all elements presented as links which use JavaScript event handlers to make the element emulate a link:
Check if the programmatically determined role of the element is link
.
Check if the emulated link can be activated using the keyboard.
If check #1 is false then this failure condition applies and the content fails Success Criteria 1.3.1 and 4.1.2.<br></br> If check #2 is false then this failure condition applies and the content fails Success Criteria 2.1.1 and 2.1.3.