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

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

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, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business