teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

「aria-hidden属性」の節を追記

2017/10/29 06:39

投稿

think49
think49

スコア18194

answer CHANGED
@@ -11,4 +11,41 @@
11
11
  ```
12
12
 
13
13
  - [6.1 The hidden attribute - HTML Standard 日本語訳](https://momdo.github.io/html/interaction.html#the-hidden-attribute)
14
- - [hidden attribute - Can I use...](http://caniuse.com/#feat=hidden)
14
+ - [hidden attribute - Can I use...](http://caniuse.com/#feat=hidden)
15
+
16
+ ### aria-hidden属性
17
+
18
+ > ```HTML
19
+ > <i style="display:block" id="title_checker_A" class="fa fa-circle" aria-hidden="true"></i>
20
+ > <i style="display:none" id="title_checker_B" class="fa fa-check-square" aria-hidden="true"></i>
21
+ > ```
22
+
23
+ **aria-hidden属性**と隠された要素の対応関係が合致していないようです。
24
+ aria-hidden属性は要素が隠されている事を表す属性です。
25
+
26
+ - [aria-hidden (ステート) - Accessible Rich Internet Applications (WAI-ARIA) 1.1 日本語訳](https://momdo.github.io/wai-aria-1.1/#aria-hidden)
27
+
28
+ ですので、aria-hidden="true" は描画されないようにする必要があるわけですが、このHTMLでは**aria-hidden="true" でブロックボックスとして描画される**こととなり、対応関係がおかしなことになっています。
29
+ 最もスマートな解決法は「CSSの属性セレクタで制御すること」です。
30
+
31
+ ```CSS
32
+ #title_checker_A, #title_checker_B {
33
+ display: block;
34
+ }
35
+
36
+ [aria-hidden="true"] {
37
+ display: none;
38
+ }
39
+ ```
40
+
41
+ `[aria-hidden="true"]` によって、`display: none` が適用されるので、aria-hidden属性の値を書き換えるだけで可視/不可視をスイッチさせることが出来ます。
42
+
43
+ ```JavaScript
44
+ document.getElementById('title_checker_A').setAttribute('aria-hidden', 'true');
45
+ ```
46
+
47
+ ### 更新履歴
48
+
49
+ - 2017/10/29 15:39 「aria-hidden属性」の節を追記
50
+
51
+ Re: SugiuraY さん