473,387 Members | 1,486 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Style properties undefined until I define them

I have the following sample:

Expand|Select|Wrap|Line Numbers
  1. <html> <body>
  2. <div id="mydiv" style="position: absolute;"> Hello </div>
  3. <script>
  4. alert(document.getElementById("mydiv").style.top);
  5. </script>
  6. </body> </html>
The resulting message box shows nothing. If I add "top: 10px" to the style (in the div tag), then it shows "10px". That means that I can't read the top/left/height/width properties without specifying them first. But I need to position another div based on the location/size of this div, which I don't want to specify explicitly (I'm using 'float' property and its height changes based on its content). Is there a way to do this?

I basically have two divs, "float: left" for both. The height of the one on the left is determined by its content, and I need to force the height of the one on the right to be exactly the same as the one on the left (I'm turning the scroll bars on for it).
Jul 28 '09 #1
1 2574
Canabeez
126 100+
You can use this function to find a position of an object:
Expand|Select|Wrap|Line Numbers
  1. function findPosition(Object)
  2. {
  3.     if('undefined' != typeof(Object.offsetParent))
  4.     {
  5.         for(var posX=0,posY=0;Object;Object=Object.offsetParent)
  6.         {
  7.             posX += Object.offsetLeft;
  8.             posY += Object.offsetTop;
  9.         }
  10.         return [posX,posY];
  11.     }
  12.     else
  13.     {
  14.         return [Object.x,Object.y];
  15.     }
  16. }
Jul 29 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Scott J. McCaughrin | last post by:
The following program compiles fine but elicits this message from the linker: "undefined reference to VarArray::funct" and thus fails. It seems to behave as if the static data-member:...
12
by: lawrence | last post by:
The following function correctly makes everything invisible but then fails to turn the one chosen DIV back to visible. I imagine I'm getting the syntax of the variable wrong? I've tried this with...
1
by: Rick | last post by:
I give up. I've been banging my head on the keyboard for the last half-hour over this one. Can someone please point out what the heck I'm doing wrong? I'm trying to move a block of text on screen....
54
by: Sander | last post by:
1. I was having a discussion with somebody and I think it's just religious. We are developing some software and he was looking through my code. I use if (pointer) to test a pointer for NULL. He...
19
by: Ramesh Tharma | last post by:
Hi, Is any one knows what's wrong with the following code, I was told that it will compile and run but it will crash for some values. Assume that variables are initilized. char* c; long*...
43
by: Sensei | last post by:
Hi! I'm thinking about a good programming style, pros and cons of some topics. Of course, this has nothing to do with indentation... Students are now java-dependent (too bad) and I need some...
3
by: Joe Cox | last post by:
I am having a problem with style properties for dynamic images in Mac OS X Safari. By dymanic images, I mean images allocated with the javascript 'new Image()' call. With static images (created...
47
by: Jon Slaughter | last post by:
private string name; public string Name { get { return name; } set { name = value; } } In the above, why doesn't C# just allow one to create a single directive to make a property?
9
by: Piotr K | last post by:
Ok, I tried simply everything that came to my mind and now I ran out of ideas, but to the point - take a look at the code below // GetStyle returns given style value (works fine)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.