On Github longmatthewh / ariaAwesomeForEveryone
Created by Matt Long / @matt_h_long
<div class="header">
<div class="title">The DIV Tag</div>
<div class="intro">The DIV element is the most versatile in HTML.</div>
</div>
<div class="main">
I love to use DIV tags whenever I can. They are so great! Here's some
reasons why I love them.
<div class="list">
<div>Its name is only 3 letters long.</div>
<div>They're so flexible—I can style them however I want.</div>
<div>DIV elements are supported by all browsers.</div>
</div>
</div>
<div class="footer">
Copyright 2014 The DIVmeister
</div>
<div class="header">
<div class="title">The DIV Tag</div>
<div class="intro">The DIV element is the most versatile in HTML.</div>
</div>
<div class="main">
I love to use DIV tags whenever I can. They are so great! Here's some
reasons why I love them.
<div class="list">
<div>Its name is only 3 letters long.</div>
<div>They're so flexible—I can style them however I want.</div>
<div>DIV elements are supported by all browsers.</div>
</div>
</div>
<div class="footer">
Copyright 2014 The DIVmeister
</div>
<div class="header">
<div class="title">The DIV Tag</div>
<div class="intro">The DIV element is the most versatile in HTML.</div>
</div>
<div class="main">
I love to use DIV tags whenever I can. They are so great! Here's some
reasons why I love them.
<div class="list">
<div>Its name is only 3 letters long.</div>
<div>They're so flexible—I can style them however I want.</div>
<div>DIV elements are supported by all browsers.</div>
</div>
</div>
<div class="footer">
Copyright 2014 The DIVmeister
</div>
<header>
<h1>The DIV Tag</h1>
The DIV element is the most versatile in HTML.
</header>
<main>
I love to use DIV tags whenever I can. They are so great! Here's some
reasons why I love them.
<ul>
<li>Its name is only 3 letters long.</li>
<li>They're so flexible—I can style them however I want.</li>
<li>DIV elements are supported by all browsers.</li>
</ul>
</main>
<footer>
Copyright 2014 The DIVmeister
</footer>
<a class="btn" href="#">I’m a Button</a>
<div class="btn">I’m a Button</div>
<span class="btn">I’m a Button</span>I'm a Button
Only in the tab order if an href attribute value is present. If an href attribute value is present then the <a> element should behave like a hyperlink.
*:focus not implemented consistently across browsers.
Need both to behave like a button consistently in all browsers
SPACE keypress/keydown needed to behave like a button consistently in all browsers
Will be identified as plain text.
"I’m a button" "I’m a button; clickable"
Will be identified as a link—not a button.
"I’m a button; internal link." "Link; I’m a button."
Will be identified as a button.
"I’m a button; button."
var $button = $('.btn');
$button.on('click', function() {
//do something awesome!
});
//add to tab order
$button.attr('tabindex','0');
//add handling of using ENTER or SPACE
$button.on('keydown', function(event) {
var whichKey = event.which;
if (whichKey === 13 || whichKey === 32) {
$button.click();
}
});
//add ARIA role
$button.attr('role','button');
"I’m a button. Button."
Describe the type of widget being displayed or structural landmarks.
Describe the widget and its state.
<h1>Samsung 110-Inch 4K HDTV</h1>
<ul>
<li>Product Info</li>
<li>Technical Specs</li>
<li>Additional Info</li>
</ul>
<div>
<h2>Product Info</h2>
<table>
<tbody><tr>
<th>Brand Name</th>
<td>Samsung</td>
</tr>
<tr>
<th>Dimensions</th>
<td>101.4 x 3.5 x 56 inches</td>
</tr>
</tbody></table>
</div>
<div>
<h2>Technical Specs</h2>
<table>
<tbody><tr><td>...</td></tr>
</tbody></table>
</div>
"Samsung 110-inch…; heading 1" "List with 3 items" "Product Info; list item" "Product Info; heading 2"
<h1>Samsung 110-Inch 4K HDTV</h1>
<ul>
<li>Product Info</li>
<li>Technical Specs</li>
<li>Additional Info</li>
</ul>
<div>
<h2>Product Info</h2>
<table>
<tbody><tr>
<th>Brand Name</th>
<td>Samsung</td>
</tr>
<tr>
<th>Dimensions</th>
<td>101.4 x 3.5 x 56 inches</td>
</tr>
</tbody></table>
</div>
<div>
<h2>Technical Specs</h2>
<table>
<tbody><tr><td>...</td></tr>
</tbody></table>
</div>
<h1>Samsung 110-Inch 4K HDTV</h1>
<ul role="tablist">
<li role="tab">Product Info</li>
<li role="tab">Technical Specs</li>
<li role="tab">Additional Info</li>
</ul>
<div role="tabpanel">
<h2>Product Info</h2>
<table>
<tbody><tr>
<th>Brand Name</th>
<td>Samsung</td>
</tr>
<tr>
<th>Dimensions</th>
<td>101.4 x 3.5 x 56 inches</td>
</tr>
</tbody></table>
</div>
<div role="tabpanel">
<h2>Technical Specs</h2>
<table>
<tbody><tr><td>...</td></tr>
</tbody></table>
</div>
<h1>Samsung 110-Inch 4K HDTV</h1>
<ul role="tablist">
<li role="tab">Product Info</li>
<li role="tab">Technical Specs</li>
<li role="tab">Additional Info</li>
</ul>
<div role="tabpanel">
<h2>Product Info</h2>
<table>
<tbody><tr>
<th>Brand Name</th>
<td>Samsung</td>
</tr>
<tr>
<th>Dimensions</th>
<td>101.4 x 3.5 x 56 inches</td>
</tr>
</tbody></table>
</div>
<div role="tabpanel">
<h2>Technical Specs</h2>
<table>
<tbody><tr><td>...</td></tr>
</tbody></table>
</div>
<h1>Samsung 110-Inch 4K HDTV</h1>
<ul role="tablist">
<li role="tab" aria-selected="true">Product Info</li>
<li role="tab" aria-selected="false">Technical Specs</li>
<li role="tab" aria-selected="false">Additional Info</li>
</ul>
<div role="tabpanel">
<h2>Product Info</h2>
<table>
<tbody><tr>
<th>Brand Name</th>
<td>Samsung</td>
</tr>
<tr>
<th>Dimensions</th>
<td>101.4 x 3.5 x 56 inches</td>
</tr>
</tbody></table>
</div>
<div role="tabpanel">
<h2>Technical Specs</h2>
<table>
<tbody><tr><td>...</td></tr>
</tbody></table>
</div>
<h1>Samsung 110-Inch 4K HDTV</h1>
<ul role="tablist">
<li role="tab" aria-selected="true">Product Info</li>
<li role="tab" aria-selected="false">Technical Specs</li>
<li role="tab" aria-selected="false">Additional Info</li>
</ul>
<div role="tabpanel" aria-expanded="true">
<h2>Product Info</h2>
<table>
<tbody><tr>
<th>Brand Name</th>
<td>Samsung</td>
</tr>
<tr>
<th>Dimensions</th>
<td>101.4 x 3.5 x 56 inches</td>
</tr>
</tbody></table>
</div>
<div role="tabpanel" aria-expanded="false">
<h2>Technical Specs</h2>
<table>
<tbody><tr><td>...</td></tr>
</tbody></table>
</div>
<h1>Samsung 110-Inch 4K HDTV</h1>
<ul role="tablist">
<li role="tab" aria-selected="true">Product Info</li>
<li role="tab" aria-selected="false">Technical Specs</li>
<li role="tab" aria-selected="false">Additional Info</li>
</ul>
<div role="tabpanel" aria-expanded="true" aria-hidden="false">
<h2>Product Info</h2>
<table>
<tbody><tr>
<th>Brand Name</th>
<td>Samsung</td>
</tr>
<tr>
<th>Dimensions</th>
<td>101.4 x 3.5 x 56 inches</td>
</tr>
</tbody></table>
</div>
<div role="tabpanel" aria-expanded="false" aria-hidden="true">
<h2>Technical Specs</h2>
<table>
<tbody><tr><td>...</td></tr>
</tbody></table>
</div>
<h1>Samsung 110-Inch 4K HDTV</h1>
<ul role="tablist">
<li role="tab" aria-selected="true">Product Info</li>
<li role="tab" aria-selected="false">Technical Specs</li>
<li role="tab" aria-selected="false">Additional Info</li>
</ul>
<div role="tabpanel" aria-expanded="true" aria-hidden="false">
<h2>Product Info</h2>
<table>
<tbody><tr>
<th>Brand Name</th>
<td>Samsung</td>
</tr>
<tr>
<th>Dimensions</th>
<td>101.4 x 3.5 x 56 inches</td>
</tr>
</tbody></table>
</div>
<div role="tabpanel" aria-expanded="false" aria-hidden="true">
<h2>Technical Specs</h2>
<table>
<tbody><tr><td>...</td></tr>
</tbody></table>
</div>
<h1>Samsung 110-Inch 4K HDTV</h1>
<ul role="tablist">
<li role="tab" aria-selected="true" aria-controls="prod-info">Product Info</li>
<li role="tab" aria-selected="false" aria-controls="tech-specs">Technical Specs</li>
<li role="tab" aria-selected="false" aria-controls="add-info">Additional Info</li>
</ul>
<div role="tabpanel" aria-expanded="true" aria-hidden="false" id="prod-info">
<h2>Product Info</h2>
<table>
<tbody><tr>
<th>Brand Name</th>
<td>Samsung</td>
</tr>
<tr>
<th>Dimensions</th>
<td>101.4 x 3.5 x 56 inches</td>
</tr>
</tbody></table>
</div>
<div role="tabpanel" aria-expanded="false" aria-hidden="true" id="tech-specs">
<h2>Technical Specs</h2>
<table>
<tbody><tr><td>...</td></tr>
</tbody></table>
</div>
<h1>Samsung 110-Inch 4K HDTV</h1>
<ul role="tablist">
<li role="tab" aria-selected="true" aria-controls="prod-info" id="prod-info-tab">Product Info</li>
<li role="tab" aria-selected="false" aria-controls="tech-specs" id="tech-specs-tab">Technical Specs</li>
<li role="tab" aria-selected="false" aria-controls="add-info" id="add-info-tab">Additional Info</li>
</ul>
<div role="tabpanel" aria-expanded="true" aria-hidden="false" id="prod-info" aria-labelledby="prod-info-tab">
<h2>Product Info</h2>
<table>
<tbody><tr>
<th>Brand Name</th>
<td>Samsung</td>
</tr>
<tr>
<th>Dimensions</th>
<td>101.4 x 3.5 x 56 inches</td>
</tr>
</tbody></table>
</div>
<div role="tabpanel" aria-expanded="false" aria-hidden="true" id="tech-specs" aria-labelledby="tech-specs-tab">
<h2>Technical Specs</h2>
<table>
<tbody><tr><td>...</td></tr>
</tbody></table>
</div>
"Samsung 110-inch…; heading 1" "List with 3 items" "Product Info; list item" "Product Info; heading 2"
"Samsung 110-inch…; heading 1" "Product Info; selected tab 1 of 3"
"Samsung 110-inch…; heading 1" "List with 3 items" "Product Info; list item" "Product Info; heading 2"
<h1>Guitar Brands</h1>
<ul>
<li>
<button class="toggle collapsed"></button>
<h2>Fender</h2>
<ul>
<li>
<button class="toggle collapsed"></button>
<h3>Electric</h3>
<ul>
<li>Stratocaster</li>
<li>Telecaster</li>
<li>Jaguar</li>
</ul>
</li>
<li>
<button class="toggle collapsed"></button>
<h3>Acoustic</h3>
<ul>
<li>Dreadnought</li>
<li>Folk</li>
<li>Mandolin</li>
</ul>
</li>
</ul>
</li>
</ul>
<h1>Guitar Brands</h1>
<ul role="tree">
<li role="treeitem">
<button class="toggle collapsed"></button>
<h2>Fender</h2>
<ul role="group">
<li role="treeitem">
<button class="toggle collapsed"></button>
<h3>Electric</h3>
<ul role="group">
<li role="treeitem">Stratocaster</li>
<li role="treeitem">Telecaster</li>
<li role="treeitem">Jaguar</li>
</ul>
</li>
<li role="treeitem">
<button class="toggle collapsed"></button>
<h3>Acoustic</h3>
<ul role="group">
<li role="treeitem">Dreadnought</li>
<li role="treeitem">Folk</li>
<li role="treeitem">Mandolin</li>
</ul>
</li>
</ul>
</li>
</ul>
<h1>Guitar Brands</h1>
<ul role="tree">
<li role="treeitem" aria-level="1" aria-expanded="false">
<button class="toggle collapsed"></button>
<h2>Fender</h2>
<ul role="group">
<li role="treeitem" aria-level="2" aria-expanded="false">
<button class="toggle collapsed"></button>
<h3>Electric</h3>
<ul role="group">
<li role="treeitem" aria-level="3">Stratocaster</li>
<li role="treeitem" aria-level="3">Telecaster</li>
<li role="treeitem" aria-level="3">Jaguar</li>
</ul>
</li>
<li role="treeitem" aria-level="2" aria-expanded="false">
<button class="toggle collapsed"></button>
<h3>Acoustic</h3>
<ul role="group">
<li role="treeitem" aria-level="3">Dreadnought</li>
<li role="treeitem" aria-level="3">Folk</li>
<li role="treeitem" aria-level="3">Mandolin</li>
</ul>
</li>
</ul>
</li>
</ul>
<h1 id="guitar-brands">Guitar Brands</h1>
<ul role="tree" aria-labeledby="guitar-brands">
<li role="treeitem" aria-level="1" aria-expanded="false">
<button class="toggle collapsed"></button>
<h2 id="fender">Fender</h2>
<ul role="group" aria-labeledby="fender">
<li role="treeitem" aria-level="2" aria-expanded="false">
<button class="toggle collapsed"></button>
<h3 id="electric">Electric</h3>
<ul role="group" aria-labeledby="electric">
<li role="treeitem" aria-level="3">Stratocaster</li>
<li role="treeitem" aria-level="3">Telecaster</li>
<li role="treeitem" aria-level="3">Jaguar</li>
</ul>
</li>
<li role="treeitem" aria-level="2" aria-expanded="false">
<button class="toggle collapsed"></button>
<h3 id="acoustic">Acoustic</h3>
<ul role="group" aria-labeledby="acoustic">
<li role="treeitem" aria-level="3">Dreadnought</li>
<li role="treeitem" aria-level="3">Folk</li>
<li role="treeitem" aria-level="3">Mandolin</li>
</ul>
</li>
</ul>
</li>
</ul>
<h1 id="guitar-brands">Guitar Brands</h1>
<ul role="tree" aria-labeledby="guitar-brands">
<li role="treeitem" aria-level="1" aria-expanded="false">
<button class="toggle collapsed"></button>
<h2 id="fender">Fender</h2>
<ul role="group" aria-labeledby="fender">
<li role="treeitem" aria-level="2" aria-expanded="false">
<button class="toggle collapsed"></button>
<h3 id="electric">Electric</h3>
<ul role="group" aria-labeledby="electric">
<li role="treeitem" aria-level="3">Stratocaster</li>
<li role="treeitem" aria-level="3">Telecaster</li>
<li role="treeitem" aria-level="3">Jaguar</li>
</ul>
</li>
<li role="treeitem" aria-level="2" aria-expanded="false">
<button class="toggle collapsed"></button>
<h3 id="acoustic">Acoustic</h3>
<ul role="group" aria-labeledby="acoustic">
<li role="treeitem" aria-level="3">Dreadnought</li>
<li role="treeitem" aria-level="3">Folk</li>
<li role="treeitem" aria-level="3">Mandolin</li>
</ul>
</li>
</ul>
</li>
</ul>
<h1 id="guitar-brands">Guitar Brands</h1>
<ul role="tree" aria-labeledby="guitar-brands" aria-activedescendant="n-0">
<li role="treeitem" aria-level="1" aria-expanded="false" aria-selected="true" id="n-0">
<button class="toggle collapsed"></button>
<h2 id="fender">Fender</h2>
<ul role="group" aria-labeledby="fender">
<li role="treeitem" aria-level="2" aria-expanded="false" aria-selected="false" id="n-0-0">
<button class="toggle collapsed"></button>
<h3 id="electric">Electric</h3>
<ul role="group" aria-labeledby="electric">
<li role="treeitem" aria-level="3" aria-selected="false" id="n-0-0-0">Stratocaster</li>
<li role="treeitem" aria-level="3" aria-selected="false" id="n-0-0-1">Telecaster</li>
<li role="treeitem" aria-level="3" aria-selected="false" id="n-0-0-2">Jaguar</li>
</ul>
</li>
<li role="treeitem" aria-level="2" aria-expanded="false" aria-selected="false" id="n-0-1">
<button class="toggle collapsed"></button>
<h3 id="acoustic">Acoustic</h3>
<ul role="group" aria-labeledby="acoustic">
<li role="treeitem" aria-level="3" aria-selected="false" id="n-0-1-0">Dreadnought</li>
<li role="treeitem" aria-level="3" aria-selected="false" id="n-0-1-1">Folk</li>
<li role="treeitem" aria-level="3" aria-selected="false" id="n-0-1-2">Mandolin</li>
</ul>
</li>
</ul>
</li>
</ul>
ul[role="tree"] {
list-style-type: none;
&:focus {
outline: 1px dotted #0000ff;
}
li {
list-style-type: none;
&[aria-selected="true"] {
outline: none;
}
&[aria-expanded="false"] > ul {
display: none;
}
&[aria-expanded="true"] > ul {
display: block;
}
}
}
var $button= $('[role="button"]');
$button.on('click', function() {
//do something awesome!
});