jQuery .each 仅针对第一个 h4 添加到 aria-label
jQuery .each to target only first h4 to add to aria-label
以下将所有 h4 文本添加到 aria-label(感谢 Tyler)。我只想添加与每个标签相关的 h4 文本。
var prodname = $(".checkbox").closest("tr").find("td.product-shortdesc h4:first").text();
$("td.select .checkbox").attr("aria-label", prodname);
目前添加
<input class="checkbox" type="checkbox" style="" aria-label="name_1 name_2 name_3">
感谢您的帮助
使用each方法
https://api.jquery.com/each/
$(".checkbox").each(function(){
var prodname = $(this).closest("tr").find("td.product-shortdesc h4:first").text();
$(this).attr("aria-label", prodname);
});
以下将所有 h4 文本添加到 aria-label(感谢 Tyler)。我只想添加与每个标签相关的 h4 文本。
var prodname = $(".checkbox").closest("tr").find("td.product-shortdesc h4:first").text();
$("td.select .checkbox").attr("aria-label", prodname);
目前添加
<input class="checkbox" type="checkbox" style="" aria-label="name_1 name_2 name_3">
感谢您的帮助
使用each方法 https://api.jquery.com/each/
$(".checkbox").each(function(){
var prodname = $(this).closest("tr").find("td.product-shortdesc h4:first").text();
$(this).attr("aria-label", prodname);
});