[ARIA] Add aria-expanded to add semantic value and styling
2024-09-01 05:27:36
In this lesson, we will be going over the attribute aria-expanded
. Instead of using a class like .open
we are going to use the aria-expanded
attribute to style.
This accomplished double duty because we have semantic value and visual indicators that a button is open and closed.
To test this, I opened up Safari and used CMD + F5 to turn VoiceOver on.
- An Introduction to ARIA States
- w3c Using aria-expanded to indicate the state of a collapsible element
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link rel="stylesheet" href="css/style.css" />
<title>Egghead Aria Expanded</title>
</head>
<body>
<h1>Aria Expanded Demo</h1>
<button class="pop-up__open">Helpful links</button>
<ul class="pop-up__items">
<li>
<a href="http://google.com/">Google</a>
</li>
<li>
<a href="http://google.com/">Stack Overflow</a>
</li>
<li>
<a href="https://dev.to/">Dev.to</a>
</li>
</ul>
<script>
const showButton = document.querySelector(".pop-up__open");
showButton.setAttribute("aria-expanded", false); showButton.addEventListener("click", () => {
const ariaExpanded = showButton.getAttribute("aria-expanded"); // This will return a string if (ariaExpanded === "true") {
showButton.setAttribute("aria-expanded", false);
} else {
showButton.setAttribute("aria-expanded", true);
}
});
</script>
</body>
</html>
最新文章
- 从零开始学Python第七周:面向对象进阶(需修改)
- 标准W3C盒子模型和IE盒子模型
- WxInput模块则比较彻底的解决了这个问题
- hdu 1250 Hat&#39;s Fibonacci
- PHP中的cookie
- FileZilla无法确定拖放操作的目标,由于shell未正确安装
- Android的横竖屏切换
- C++----练习--while求和
- centos5.8本地安装yum资源,安装软件包
- JS中encodeURI,escape,encodeURIComponent区别
- java读取请求中body数据
- Request和Response
- MySQL 8 新特性之持久化全局变量的修改
- 关于BDD100k数据输入处理mask变为56*56
- 一起学习造轮子(一):从零开始写一个符合Promises/A+规范的promise
- flutter学习地址
- 在Java中动态传参调用Python脚本
- [Java in NetBeans] Lesson 05. Method/function
- 几种常见数据库的driverClassName和url
- Educational Codeforces Round 61 F 思维 + 区间dp