PDA

View Full Version : Simple DHTML not working



Eric Marthinsen
06-23-2006, 11:20 PM
Can anyone explain why this isn't working:

<html>

<head>

<title>Test Page</title>

<script language="javascript" type="text/javascript">

function Init()
{

var foo = document.getElementById("title");

foo.InnerText = "HELLO";
}
</script>
</head>
<body onload="Init();">

<h1 id="title">Title</h1>
</body>
</html>

Eric Marthinsen
06-23-2006, 11:22 PM
Nevermind. I just realized I was using InnerText instead of innerText. I've been in the world of Pascal casing for a while now.

Twey
06-23-2006, 11:24 PM
"innerText" exists only in IE, and so should not be used. That should be written like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Test Page</title>
<script type="text/javascript">
function Init()
{
var foo = document.getElementById("title");
foo.innerHTML = "HELLO";
}
</script>
</head>
<body onload="Init();">
<h1 id="title">Title</h1>
</body>
</html>