spacer
Yehuda Shiran August 15, 2000
Expando Properties
Tips: August 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

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

The default behavior of Internet Explorer is that you can add arbitrary properties to any object on the page. These properties are called expando properties. Starting from Version 5, you can protect yourself from creating arbitrary properties. This self protection prevents you from creating new properties when you intend to set existing properties, but fail because of typos and wrong cases. For example, if you want to set the borderColor property of a style object and you type instead bordercolor, a new expando property will be created. As a consequence, the border color will not be changed according to your specifications and you will have difficult time figuring out why.

To protect you from doing such mistakes, you should set the expando property to false:

document.expando = false;
To reset it back:

document.expando = true;
If you try to create an arbitrary property when document.expando is false, you'll get an error message that the object does not support such property. The following two lines yield no error (myDiv is the ID of a DIV element somewhere on the page):

document.expando = true;
myDiv.myProperty = myValue;
while the following two lines yields an error message telling you that the object myDiv does not support the property myProperty:

document.expando = false;
myDiv.myProperty = myValue;

People who read this tip also read these tips:

Look for similar tips by subject:

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