Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Difficulty Obtaining Properties Of A DIV Object

Status
Not open for further replies.

JTeagle

Programmer
May 30, 2000
49
GB
I'm afraid I'm having difficulty with what should be a fairly fundamental task: obtaining the properties of a DIV object at run time.<br><br>Using a standard style sheet, which names position AND size for a DIV (<FONT FACE=monospace>#TestDIV {left: 100px; top: 20px; width: 100px; height: 20px;}</font> ), I embed a standard DIV into an HTML page:<br><br><FONT FACE=monospace>&lt;DIV ID=&quot;TestDIV&quot;&gt;<br>&lt;SELECT NAME=&quot;TestComboBox&quot;&gt;<br>&lt;OPTION VALUE=&quot;One&quot;&gt;One&lt;/OPTION&gt;<br>&lt;OPTION VALUE=&quot;Two&quot;&gt;Two&lt;/OPTION&gt;<br>&lt;/SELECT&gt;<br>&lt;/DIV&gt;</font><br><br>The DIV initially appears correctly. The problem is, I can't get its attributes properly later. Here's how I am trying:<br><br><FONT FACE=monospace>function GetDIVObject(strID)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;var Object = null ;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;switch (g_iBrowser)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case 1 : // IE.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Object = document.all[strID].style ;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break ;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case 2 : // Netscape.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Object = document.layers[strID];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break ;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;return Object ;<br>}</font><br><br>And then I am trying to see the values:<br><br><FONT FACE=monospace>var Object ;<br><br>Object = GetDIVObject(&quot;TestDIV&quot;);<br>document.writeln(&quot;&quot; + Object.xxx);</font><br><br>In Netscape, &quot;left&quot; and &quot;top&quot; correctly return 100 and 20, but &quot;width&quot; and &quot;height&quot; return &quot;undefined&quot;.<br>In IE, &quot;pixelLeft&quot; and &quot;pixelTop&quot; return 0, and &quot;pixelWidth&quot; and &quot;pixelHeight&quot; return either &quot;undefined&quot; or a blank (I can't remember which right now).<br><br>What am I doing wrong?<br><br>(Sorry about the length of the question, I needed to give as much info as possible).<br><br>
 
try using getElementById(). send the id name through this predefined function and it will return the object.&nbsp;&nbsp;It is fully supported by netscape, but only partially supported by IE, a first for netscape. <p>theEclipse<br><a href=mailto:eclipse_web@hotmail.com>eclipse_web@hotmail.com</a><br><a href=robacarp.webjump.com>robacarp.webjump.com</a><br>**-Trying to build a documentation of a Javascript DOM, crossbrowser, of course. E-mail me if you know of any little known events and/or methods, etc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top