spacer
Yehuda Shiran December 18, 2000
Initializing Element Coordinates
Tips: December 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 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 >
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