Setting innerHTML
The innerHTML property of elements in IE is not part of the W3C DOM. Nevertheless, in response to customers' requests, Mozilla- and Gecko-based browsers (such as Netscape 6) decided to support it in builds dated May 19, 2000 or later (Mozilla M16 and later, Netscape 6 PR2 and later). Let's look at an example. We want to update a counter by clicking a button. Let's look at the following code sample:
<DIV ID="counter">Number of clicks = 0</DIV>
<FORM>
<INPUT TYPE="button" VALUE="Increment Counter"
onclick="updateMessage()">
</FORM>
<SCRIPT LANGUAGE="JavaScript">
<!--
var hits = 0;
function updateMessage() {
hits += 1;
document.getElementById("counter").innerHTML =
"Number of clicks = " + hits;
}
// -->
</SCRIPT>
which renders like this:
Number of clicks = 0
        
Next: How to move objects horizontally
|