Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Find left position of table cell

Reply
Thread Tools

Find left position of table cell

 
 
ted
Guest
Posts: n/a
 
      01-15-2005
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.createElement("td");
cell.appendChild("sometext");
cell.className = "cellStyle";
tableRow = document.getElementById(theTableRowId);
tableRow.appendChild(cell);

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

Any help appreciated. Thanks.

-Ted



 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      01-15-2005


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.createElement("td");
> cell.appendChild("sometext");
> cell.className = "cellStyle";
> tableRow = document.getElementById(theTableRowId);
> tableRow.appendChild(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.offsetLeft;
coords.y += element.offsetTop;
element = element.offsetParent;
}
// check coords.x, coords.y here
Doesn't depend on whether it is a cell.


--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
ted
Guest
Posts: n/a
 
      01-17-2005
Thanks Martin.

"Martin Honnen" <(E-Mail Removed)> wrote in message
news:41e93e2c$0$23139$(E-Mail Removed)-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.createElement("td");
>> cell.appendChild("sometext");
>> cell.className = "cellStyle";
>> tableRow = document.getElementById(theTableRowId);
>> tableRow.appendChild(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.offsetLeft;
> coords.y += element.offsetTop;
> element = element.offsetParent;
> }
> // check coords.x, coords.y here
> Doesn't depend on whether it is a cell.
>
>
> --
>
> Martin Honnen
> http://JavaScript.FAQTs.com/



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help on table align on left of page vs left hanging indent =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?= XML 2 07-16-2007 11:46 AM
How to put some space at the left margin of a table cell? Martin HTML 3 06-22-2006 02:41 AM
position of a control in a table cell =?Utf-8?B?R1Y=?= ASP .Net 2 06-07-2006 08:19 PM
Table Cell text position Mark A. Sam ASP .Net 0 04-04-2006 02:38 AM
How can I find the name of the parent table from a table cell? jklimek@gmail.com Javascript 7 07-10-2005 11:27 PM



Advertisments