473,382 Members | 1,814 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,382 software developers and data experts.

element position in nested tables??!!

greetings

I had a javascript that was reliably telling me the position of an
image on a page, and now its not. I was using the script to draw a
bounding box that followed the mouse around over the image, and when
you clicked the mouse the x-y position of the image pixel the mouse was
over was posted back in the form. I just changed the layout of the
page so that the image is now in a table that is nested in another
table, and the old reliable script is now giving me the position of the
image as the upper left corner of the outer table a couple hundred
pixels in the wrong direction. When i first wrote the script i googled
around and people were saying you had to traverse up the document tree
to find the top (document level) offsetParent element to determine the
true offsetLeft and offsetTop of an element, which is what i did, and
which is what seemed to work for a while. BUT, once i nested these
tables that doesn't seem to work. Is this a common problem, or have i
just screwed up somewhere??

Here's the script i was using to find the position:

////

function Point(xpos, ypos){
this.x=xpos;
this.y=ypos;
}

function findPosition(element){
var currPt = new Point(0, 0);
if(element.offsetParent){
// just march up the document tree
while(element.offsetParent){
currPt.x = element.offsetLeft;
currPt.y = element.offsetTop;
element = element.offsetParent;
}
}else{
if(element.x)
currPt.x = element.x;
if(element.y)
currPt.y = element.y;
}
return currPt;
}

////

-thanks

-travis

Jul 23 '05 #1
1 1820


tr***********@hotmail.com wrote:

function findPosition(element){
var currPt = new Point(0, 0);
if(element.offsetParent){
// just march up the document tree
while(element.offsetParent){
Try
while (element) {
currPt.x = element.offsetLeft;
currPt.y = element.offsetTop;
element = element.offsetParent;
}


otherwise your code misses out on the last element in the offset
hierarchy I think.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Markus Ernst | last post by:
Hello Reading the follwing document: http://www.w3.org/TR/WD-positioning-970131#In-flow it seems very clear that position:relative should be relative to the parent element. So in the following...
4
by: mike eli | last post by:
Hi, I have several absolute positioned elements inside an absolute positioned DIV. I would like one of the nested elements to have a dynamic width. I set it's left and right attributes to 5, so...
1
by: Knut | last post by:
Hello everybody. This is my first attempt at Javascript, something that is long overdue. But please bear that in mind, and have mercy (= My question is simple: I'm doing a dropdown menu...
5
by: Patient Guy | last post by:
In my reading of the Strict and Transitional DTD for HTML 4.0, the table row (TR) elements are contained within table section elements: THEAD, TFOOT, and TBODY. The table section elements are...
2
by: Fred Flintstone | last post by:
Why not? Why can't I put a table within paragraph tags? Also: "Element DIV cannot be nested within element 'u'." I can't underline something within div tags? Why not? Thanks! :)
8
by: VK | last post by:
Can be multiple instances of element used as the root element? That's a curly way of asking, but I did not come up with a better sentence, sorry. What I mean is with a document like: <?xml...
4
by: john | last post by:
Hi to All, I am new to html authoring, so sorry if my terminology is not correct or exact. I would like to position a footer div to the bottom of the browser window. As I research in the web...
2
by: steven acer | last post by:
i'm illiterate when it comes to javascript and browser issues, i'm trying to code a small help module for my java app.i've went far enough coding all the server side but i'm stuck with javascript...
0
by: Microsoft Newsserver | last post by:
Im using IE 6/7 / ASP.NET / Javascript. I need to determine the absolute position of elements on my page client side. In summart, I need to know if an event triggered mouse position appears...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.