回答編集履歴

1

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

2017/10/29 06:39

投稿

think49
think49

スコア18166

test CHANGED
@@ -25,3 +25,77 @@
25
25
  - [6.1 The hidden attribute - HTML Standard 日本語訳](https://momdo.github.io/html/interaction.html#the-hidden-attribute)
26
26
 
27
27
  - [hidden attribute - Can I use...](http://caniuse.com/#feat=hidden)
28
+
29
+
30
+
31
+ ### aria-hidden属性
32
+
33
+
34
+
35
+ > ```HTML
36
+
37
+ > <i style="display:block" id="title_checker_A" class="fa fa-circle" aria-hidden="true"></i>
38
+
39
+ > <i style="display:none" id="title_checker_B" class="fa fa-check-square" aria-hidden="true"></i>
40
+
41
+ > ```
42
+
43
+
44
+
45
+ **aria-hidden属性**と隠された要素の対応関係が合致していないようです。
46
+
47
+ aria-hidden属性は要素が隠されている事を表す属性です。
48
+
49
+
50
+
51
+ - [aria-hidden (ステート) - Accessible Rich Internet Applications (WAI-ARIA) 1.1 日本語訳](https://momdo.github.io/wai-aria-1.1/#aria-hidden)
52
+
53
+
54
+
55
+ ですので、aria-hidden="true" は描画されないようにする必要があるわけですが、このHTMLでは**aria-hidden="true" でブロックボックスとして描画される**こととなり、対応関係がおかしなことになっています。
56
+
57
+ 最もスマートな解決法は「CSSの属性セレクタで制御すること」です。
58
+
59
+
60
+
61
+ ```CSS
62
+
63
+ #title_checker_A, #title_checker_B {
64
+
65
+ display: block;
66
+
67
+ }
68
+
69
+
70
+
71
+ [aria-hidden="true"] {
72
+
73
+ display: none;
74
+
75
+ }
76
+
77
+ ```
78
+
79
+
80
+
81
+ `[aria-hidden="true"]` によって、`display: none` が適用されるので、aria-hidden属性の値を書き換えるだけで可視/不可視をスイッチさせることが出来ます。
82
+
83
+
84
+
85
+ ```JavaScript
86
+
87
+ document.getElementById('title_checker_A').setAttribute('aria-hidden', 'true');
88
+
89
+ ```
90
+
91
+
92
+
93
+ ### 更新履歴
94
+
95
+
96
+
97
+ - 2017/10/29 15:39 「aria-hidden属性」の節を追記
98
+
99
+
100
+
101
+ Re: SugiuraY さん