Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 635
vaanipala Avatar asked Sep 24 '12 08:09

vaanipala


2 Answers

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";
like image 143
xdazz Avatar answered Oct 21 '22 04:10

xdazz


use

document.getElementsByTagName("p")[0].innerHTML="hello my name is vaani";
like image 36
Patriks Avatar answered Oct 21 '22 03:10

Patriks