javascript TypeError: document.getElementsByTagName(“p”)[0].innerHtml is not a function

梦想的初衷 提交于 2019-11-26 17:14:49

问题


I'm getting the following error for a simple function below:

TypeError: document.getElementsByTagName("p")[0].innerHtml is not a function

I'm just trying to understand the usage of getElementsByTagName.

function myFunc(){
document.getElementsByTagName("p")[0].innerHtml("hello my name is vaani");
}
</script>
</head>

<body onload="myFunc();">
<p></p>
<p></p>
<p></p>
</body>

Can someone tell me on where i'm going wrong?


回答1:


innerHTML but not innerHtml, and it is not a function, you should set the string to this property.

document.getElementsByTagName("p")[0].innerHTML = "hello my name is vaani";



回答2:


use

document.getElementsByTagName("p")[0].innerHTML="hello my name is vaani";


来源:https://stackoverflow.com/questions/12561734/javascript-typeerror-document-getelementsbytagnamep0-innerhtml-is-not-a-f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!