Error parsing value for property 'top'

T

Tom

I have a function which finds the x and y coordinate of any object in
the document by referring to offsetLeft or offsetTop value of the
object's offsetParent, all the way to the top of the DOM, i.e.:

function get_y(obj) {
var coord = 0;
while (obj.offsetParent) {
coord += obj.offsetTop;
obj = obj.offsetParent;
}
return coord;
}

function get_x(obj) {
/* same as above function, but with offsetLeft in place of offsetTop
*/
}

Now, I've tested this function out many, many times on documents built
using table models, and it works perfectly. However, I tried to import
the same function to a document using a CSS model without any tables
and it fails on the y-coord function ONLY -- the x-coord function
(offsetLeft) works just as it would on a document using the table
model, but the y-coord function produces the following error in a CSS
model:

"Line 0: Error parsing value for property 'top'; Declaration dropped"
(moz error -- IE returns "Invalid argument Line 0")

I'm unable to figure out what the problem is. I'm assuming I've left
out a certain required parameter in my stylesheet, but I don't know
what it could be!

Any insight would be appreciated!
 
M

Martin Honnen

Tom wrote:

"Line 0: Error parsing value for property 'top'; Declaration dropped"
(moz error

That error message is given by Mozilla's CSS parser and essentially
means that you/your stylesheet(s) give an incorrect value for the CSS
top property e.g. instead of having
top: 20px;
you might have only
top: 20;
which is not correct CSS. So check your stylesheet or your script
setting the CSS top property to supply a proper CSS value (i.e. number
plus unit).
 
T

Tom

That error message is given by Mozilla's CSS parser and essentially
means that you/your stylesheet(s) give an incorrect value for the CSS
top property e.g. instead of having
top: 20px;
you might have only
top: 20;
which is not correct CSS. So check your stylesheet or your script
setting the CSS top property to supply a proper CSS value (i.e. number
plus unit).

Which object though? I don't have the top property defined anywhere in
my stylesheet (all the elements are floating).

The function successfully finds the offsetTop for all div elements, but
somewhere near the top of the DOM this error pops up. The fact that
position is not defined anywhere doesn't seem to affect the function's
ability to get the offsetLeft value, but it does for offsetTop. Any
thoughts?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top