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

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Google Going Native With Chrome
Mozilla Fixes Firefox Flaws as 3.5 Release Nears
Microsoft and Novell Still Bosom Buddies

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

webref The latest from WebReference.com Browse >
XML and PHP Simplified · Creating a ASP.NET Contact Form · Data Filtering with PHP
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Intel to Host Live Nehalem Q&A · 12 Tips to Troubleshoot Network File-Sharing · 10 Tips for Selling on Kijiji