[英]How to change the text inside of p tag with a class by using innerHTML
I want to change the text inside a p
tag which has a class info
by using innerHTML, but it does not work properly. 我想通过使用innerHTML更改具有类
info
的p
标记内的文本,但是无法正常工作。 Is there somthing wrong in this code? 这段代码有什么问题吗? Thanks.
谢谢。
Javascript; JavaScript的;
var pokeDescription = document.getElementsByClassName("info");
for(var n=0; n < pokeDescription; n++){
pokeDescription[n].innerHTML = data.info.description;
}
HTML; HTML;
<p class="info">Description here</p>
You forgot .length
你忘了
.length
var pokeDescription = document.getElementsByClassName("info");
for(var n=0; n < pokeDescription.length; n++){
pokeDescription[n].innerHTML = data.info.description;
}
You are missing the length
field in your loop: 您在循环中缺少
length
字段:
var pokeDescription = document.getElementsByClassName("info");
for(var n=0; n < pokeDescription.length; n++){
pokeDescription[n].innerHTML = data.info.description;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.