spacer

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

home / experts / javascript / column3


Updating Existing Text

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

First, take another look at our <SPAN> definition from the previous section of the column:

<SPAN ID="banner" STYLE="position: absolute;"></SPAN>

The ID attribute is similar to the NAME attribute in that it defines the HTML element's individual name. The ID attribute is used to reference the element in JavaScript. In Navigator, document.banner reflects the element, while document.all.banner, or simply banner, represents it in Internet Explorer.

By now, you probably understand why we introduced browser detection in the first section of this column. Microsoft and Netscape agree on CSS, but disagree on the object model. Navigator treats a positioned element as a new browser window, so you can write to its document object, whereas Internet Explorer features a property that reflects the element's inner content (innerHTML). The following function sets the content of a specific element:

function display(id, str) {
  if (NS4) {
    with (document[id].document) {
      open();
      write(str);
      close();
    }
  } else {
    document.all[id].innerHTML = str;
  }
}

In order to rotate our banner, we'll invoke this function in the following way:

display("banner", "new code here");

http://www.internet.com

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint


Created: September 25, 1997
Revised: April 16, 1998

URL: http://www.webreference.com/js/column3/objects.html