spacer
Yehuda Shiran December 18, 2000
Initializing Element Coordinates
Tips: December 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

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

The browser-independent W3C Standard's way to set and get an element position is via the style object's left and top properties. The following strings are example values of the left and top properties: 50px, 32px, and 0px. You can initialize an element properties by the STYLE attribute of its HTML tag. Notice the left:"150px" string in the following tag definition:

<INPUT ID="button1" STYLE="position:relative; left:"250px"; visibility:'visible';" TYPE="button" 
  VALUE="Show My Visibility" onclick="handleClick1()">
Here is how this button renders:

Click the button to check its visibility. It will come out empty for both Internet Explorer and Netscape 6. Surprisingly enough, both Internet Explorer and Netscape 6 do not recognize the string format of the left and top properties, and position them at coordinates (0,0). To solve this problem, you need to use the integer format:

<INPUT ID="button2" STYLE="position:relative; left:250; visibility:'visible';" TYPE="button" 
  VALUE="Show My Visibility" onclick="handleClick2()">
and then it will render like this:

Notice that only now the button is 250 pixels to right. Click the button to check its visibility. It will come out empty for Netscape 6 and "visible" for Internet Explorer.


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