admin管理员组文章数量:1026343
I don't know why it's returning error with tagName. is subLabel wrong?
for (var ind = 0; ind < target.length; ind++)
{
var target = target[ind]
for (var ind; ind < target.childNodes.length; ind++);
{
const subLabel = target.childNodes[ind];
if (subLabel.tagName == "SPAN" || subLabel.tagName == "LI") //error line
{
//do something with label
}
typeDisplay(subLabel);
}
}
I don't know why it's returning error with tagName. is subLabel wrong?
for (var ind = 0; ind < target.length; ind++)
{
var target = target[ind]
for (var ind; ind < target.childNodes.length; ind++);
{
const subLabel = target.childNodes[ind];
if (subLabel.tagName == "SPAN" || subLabel.tagName == "LI") //error line
{
//do something with label
}
typeDisplay(subLabel);
}
}
Share
Improve this question
asked Jan 15, 2022 at 13:04
eattatoeattato
131 gold badge1 silver badge5 bronze badges
3 Answers
Reset to default 1You are using var ind
twice. Use let
instead. Read this
You are using the same variable name in both inner and outer for loop (ie. var ind
).
what you can do here is either change the variable name in the inner loop or change the variable name in the outer loop.
It's mon for nested loops, to use a different loop variable, such as while the outer loop uses var i=0;
the inner loop uses var j=0;
.
The posted code, the 2nd var ind
is duplicated, because it shares the same variable scope of the 1st var
.
I don't know why it's returning error with tagName. is subLabel wrong?
for (var ind = 0; ind < target.length; ind++)
{
var target = target[ind]
for (var ind; ind < target.childNodes.length; ind++);
{
const subLabel = target.childNodes[ind];
if (subLabel.tagName == "SPAN" || subLabel.tagName == "LI") //error line
{
//do something with label
}
typeDisplay(subLabel);
}
}
I don't know why it's returning error with tagName. is subLabel wrong?
for (var ind = 0; ind < target.length; ind++)
{
var target = target[ind]
for (var ind; ind < target.childNodes.length; ind++);
{
const subLabel = target.childNodes[ind];
if (subLabel.tagName == "SPAN" || subLabel.tagName == "LI") //error line
{
//do something with label
}
typeDisplay(subLabel);
}
}
Share
Improve this question
asked Jan 15, 2022 at 13:04
eattatoeattato
131 gold badge1 silver badge5 bronze badges
3 Answers
Reset to default 1You are using var ind
twice. Use let
instead. Read this
You are using the same variable name in both inner and outer for loop (ie. var ind
).
what you can do here is either change the variable name in the inner loop or change the variable name in the outer loop.
It's mon for nested loops, to use a different loop variable, such as while the outer loop uses var i=0;
the inner loop uses var j=0;
.
The posted code, the 2nd var ind
is duplicated, because it shares the same variable scope of the 1st var
.
本文标签: javascriptCannot read properties of undefined (reading 39tagName39)Stack Overflow
版权声明:本文标题:javascript - Cannot read properties of undefined (reading 'tagName') - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745613491a2159146.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论