各a.parent_linkからテキストを取得し、対応する各トグルボタン(button.sub-expand_collapse)にaria-labelとして適用したいと考えています。私が望む最終的な結果は、aria-expanded = trueにaria-label = close +(text)を追加し、aria-expanded = falseにaria-label = expand +(text)を追加する場合です。それぞれのテキストを取得してaria-labelに使用する
最初の部分は私にテキスト
$(".togSubList").each(function() {
var bob = $(this).find(".parent_link").text();
console.log(bob);
});
を与えるしかし、私はアリア・ラベルを追加するには、各1を得ることができません。
$(".togSubList").each(function() {
var bob = $(this).find(".parent_link").text();
//console.log(bob);
$(".sub-expand_collapse").each(function(){
$(this).attr("aria-label","expand " + bob)
});
});
HTML
<li class="sub_p01 togSubList">
<button class="sub-expand_collapse" aria-expanded="false">
<i class="fa fa-plus" aria-hidden="true"></i>
</button>
<a id="subLnk_01" class="parent_link menu_p01" href="m01_c01_p01.html"><strong>Space saving widgets</strong></a>
<ul aria-labelledby="subLnk_01" class="sub_items">
list of links
</ul>
</li>
あなたのコードは私のテストで動作します:https://jsfiddle.net/8xgtcg87/ たぶんjQueryのロードエラーがどこかにありますか? –