473,670 Members | 2,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Find left position of table cell

ted
Hi,

Was wondering if it's possible to find the left position of a table cell if
the cell is created dynamically.

I have a table with a single cell. When a button is clicked, I'd like to add
another cell to it, give the cell a class style and then find the cell's
left position.

Right now I'm using doing this:

cell = document.create Element("td");
cell.appendChil d("sometext") ;
cell.className = "cellStyle" ;
tableRow = document.getEle mentById(theTab leRowId);
tableRow.append Child(cell);

How would I get the left position of each cell added?

Any help appreciated. Thanks.

-Ted

Jul 23 '05 #1
2 11592


ted wrote:

I have a table with a single cell. When a button is clicked, I'd like to add
another cell to it, give the cell a class style and then find the cell's
left position.

Right now I'm using doing this:

cell = document.create Element("td");
cell.appendChil d("sometext") ;
cell.className = "cellStyle" ;
tableRow = document.getEle mentById(theTab leRowId);
tableRow.append Child(cell);

How would I get the left position of each cell added?


You can get the position of any element in the document the same way (in
IE 4+, Netscape 6+, Mozilla, Opera 7+) by adding the offsetLeft and
offsetTop values along the offsetParent hierarchy, e.g. assuming element
is a reference to the element
var coords = { x: 0, y: 0 };
while (element) {
coords.x += element.offsetL eft;
coords.y += element.offsetT op;
element = element.offsetP arent;
}
// check coords.x, coords.y here
Doesn't depend on whether it is a cell.
--

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

"Martin Honnen" <ma*******@yaho o.de> wrote in message
news:41******** *************** @newsread2.arco r-online.net...


ted wrote:

I have a table with a single cell. When a button is clicked, I'd like to
add another cell to it, give the cell a class style and then find the
cell's left position.

Right now I'm using doing this:

cell = document.create Element("td");
cell.appendChil d("sometext") ;
cell.className = "cellStyle" ;
tableRow = document.getEle mentById(theTab leRowId);
tableRow.append Child(cell);

How would I get the left position of each cell added?


You can get the position of any element in the document the same way (in
IE 4+, Netscape 6+, Mozilla, Opera 7+) by adding the offsetLeft and
offsetTop values along the offsetParent hierarchy, e.g. assuming element
is a reference to the element
var coords = { x: 0, y: 0 };
while (element) {
coords.x += element.offsetL eft;
coords.y += element.offsetT op;
element = element.offsetP arent;
}
// check coords.x, coords.y here
Doesn't depend on whether it is a cell.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 23 '05 #3

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

Similar topics

1
2126
by: Asra | last post by:
Hello, I have a table with width as 98% and all cell widths as 120. However, these cell widths change with resolution changes. I have to find the current cell width and its left position. Is there a browser independent way to do that? Best Regards, Asra Baig
1
1712
by: Anna K. | last post by:
Hi Experts, I'm new to JavaScript and web-based apps development, so I'll tell you right off that I don't really know my way around it as of yet. I'm trying to create a code library set with JavaScript (in DreamweaverMX) to display "buttons" with which to select pages in a gallery. I'm trying to "grey out" (and disable) the button for the current page when it is displayed. (This isn't rocket science here, but it's something that I...
1
1723
by: JimFurrow | last post by:
Heya folks, if I have a Table on a page and Cells within that table (all of this is layed out relatively), how can I calculate the Top and Left position of any particular Cell in that Table? Thanks y'all.
1
1743
by: Matt Kruse | last post by:
I've never found a function which will return me the x,y position of an object on the page reliably, cross-browser, in any type of page layout situation. So, I've been working on my own function to accomplish this. If anyone knows of a solution which already exists, please do let me know. Here is my test page so far: http://www.mattkruse.com/javascript/ObjectPositionTest.php My goal is to reliably return an object's position on the...
2
12355
by: Michael | last post by:
Need some help trying to read values from web controls - specifically *finding* the controls (like a drop down list) - that are added dynamically added within an asp:panel control. The page contains multiple panels within the form. The panels appear at different times - for our argument, let's say panel 1 appears first, users clicks a submit button and then panel 1 disappears and panel 2 appears, etc. When clicks on the submit button...
4
2612
by: Aaron Smith | last post by:
Dim dv As DataView = New DataView(FacilitiesDS1.Facilities, "", "ID ASC", DataViewRowState.CurrentRows) Dim iPos As Integer = dv.Find(dr.Item("ID")) Me.BindingContext(FacilitiesDS1, "Facilities").Position = iPos That is the code.. dr is DataRow. If dr.Item("ID") = 3, the find will return position 0, which it should have been 1, and if the ID = 2, it will return 1, which should have been 0.. The DA has a connection string that sorts it...
19
2014
by: JB | last post by:
Hi All, Why doesn't this work in Firefox but is perfect in IE6? In IE6, the text is on the same line but in Firefox, the left aligned text is on the line above the right aligned text. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html>
2
2068
by: everly | last post by:
Hi, I'm helping my friends band and making their MySpace. I messed something up and I can't figure out what it is. Everything is all out of whack on the bottom half of the page. The comments shouldn't be on the left hand side. Help please! Thanks. ____________________________________________________- <style type="text/css"> { Background Properties } table, tr, td { background-color:transparent; border:none; border-width:0;} body {...
1
2763
by: thomasv | last post by:
Hi, I want to convert the following XML (OpenOffice Calc file): <?xml version="1.0" encoding="UTF-8"?> <office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
0
8386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8814
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7415
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6213
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5683
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4209
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4390
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2799
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1792
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.