admin管理员组文章数量:1344942
I'm trying to add aria-required="true" attributes to some form elements from ninja forms in wordpress. I'm using a header/footer script inject plugin. But I can't seem to get my code to actually work. Any help would be greatly appreciated!
/contact/
<script>
function codeAddress() {
var x = document.getElementsByClassName("nf-element");
var i;
for (i = 0; i < x.length; i++) {
x[i].addAttribute("aria-required", "true");
}
window.onload = codeAddress
}
</script>
<div class="nf-field-element">
<input id="nf-field-17" name="nf-field-17" class="ninja-forms-field nf-element" type="text" value="" placeholder="First Name">
</div>
I'm trying to add aria-required="true" attributes to some form elements from ninja forms in wordpress. I'm using a header/footer script inject plugin. But I can't seem to get my code to actually work. Any help would be greatly appreciated!
http://champion.magnet.today/contact/
<script>
function codeAddress() {
var x = document.getElementsByClassName("nf-element");
var i;
for (i = 0; i < x.length; i++) {
x[i].addAttribute("aria-required", "true");
}
window.onload = codeAddress
}
</script>
<div class="nf-field-element">
<input id="nf-field-17" name="nf-field-17" class="ninja-forms-field nf-element" type="text" value="" placeholder="First Name">
</div>
Share
Improve this question
asked Jun 12, 2017 at 15:53
Trishan KuventhirarajahTrishan Kuventhirarajah
511 gold badge1 silver badge2 bronze badges
2 Answers
Reset to default 7You need to use setAttribute. Also window.load should be outside the codeAddress
function
function codeAddress() {
var x = document.getElementsByClassName("nf-element");
var i;
for (i = 0; i < x.length; i++) {
console.log(x[i])
x[i].setAttribute("aria-required", "true");
}
}
window.onload = codeAddress
<div class="nf-field-element">
<input id="nf-field-17" name="nf-field-17" class="ninja-forms-field nf-element" type="text" value="" placeholder="First Name">
</div>
try replacing x[i].addAttribute("aria-required", "true");
with x[i].setAttribute("aria-required", "true");
本文标签: jqueryjavascript to add aria attributeStack Overflow
版权声明:本文标题:jquery - javascript to add aria attribute - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743780445a2537730.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论