【发布时间】:2022-12-02 11:08:18
【问题描述】:
I was using this page as test to check if the code works, and when I hit enter the code does work by checking all checkboxes and making all labels bold but when I refresh the page and try the same thing again it doesn't work anymore.
(function() {
var aa = document.getElementsByTagName("input");
var bb = document.getElementsByTagName("label");
for (var i = 0; i < aa.length; i++){
if (aa[i].type == 'checkbox')
aa[i].checked = true;
bb[i].textContent.bold();
}
})()
I tried using console.log(bb[i].textContent.bold() to check if the code detects the labels and it did the first time. The console says VM131:7 Uncaught TypeError: Cannot read properties of undefined (reading 'textContent'). I was expecting that the labels are also turned to bold after checking all the checkboxes
【问题讨论】:
标签: javascript