spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column75


Netscape 6, Part IV: DOM Differences and Commonalities with IE5.x

Developer News
OpenOffice 3.2 Lands Amid Critical Changes
Red Hat, IBM Firmly in KVM Virtualization Camp
Red Hat Talks Up Open Source Cloud Plans

The innerHTML Property

The innerHTML element property provides a convenient way to replace the contents of elements in IE. However, it is not part of the W3C DOM. Nevertheless, in response to customer 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 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 looks like this on the Web:

Number of clicks = 0

The function updateMessage() is called every time the user clicks the button. The number of hits is incremented by one, and the content of the DIV counter is updated by the innerHTML property, via a simple assignment. Notice the usage of getElementById() which is common to both Netscape 6 and Internet Explorer.

Next: A Final Word

http://www.internet.com


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

webref The latest from WebReference.com Browse >
Search Engine Optimization: Selecting and Embedding Keywords · Are Google's Language Translation Web Services Ready for Prime Time? · Installing and Using Meeplace, the Business Review CMS
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
IBM DB2 10 for z/OS: Justifying the Upgrade · Living La Vida Colo: Choosing the Right Colocation Facility · FTC Concerns over Social Media Privacy Linger


Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: January 15, 2001
Revised: January 15, 2001

URL: http://www.webreference.com/js/column75/8.html