I'm writing frame website template that uses javascript instead of frames, and I have issue with document.getElementById("contentbody").innerHTML=body[i];
line, but I don't see anything wrong with it. Dev. Console tells me TypeError: document.getElementById(...) is null
, which makes no sense, because it's returns null only if there's no element with such id (and there is).
<table style="width: inherit;">
<tr>
<td style="width: 220px;">
<h2 style="text-align: center;">titlehere</h2>
<div id='menubody' />
</td>
<td>
<h1 id='contenttitle' />
<div id='contentbody' />
</td>
</tr>
</table>
<script>
var title =
[
"<p>",
"<div>"
];
var body =
[
"<p> is for text",
"<div> is for cool text"
];
function change(i)
{
document.getElementById("contenttitle").innerHTML=title[i];
document.getElementById("contentbody").innerHTML=body[i];
}
change(0);
</script>
Any help? Suggestions?