473,395 Members | 2,079 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,395 software developers and data experts.

find position of a element in a table

Hi,

my html code is :

<div style="position:absolute;top:10px;left:10px">
<table>
<tr>
<td id="TdBarreBouton1">
<hr>
</td>
</tr>
<tr>
<td id="TdBarreBouton2">
<button id="btn_inserer">Bouton</button>
</td>
</tr>
</table>
</div>

I want to know the postion of the button.

My javascript code is :

boutonInserer = document.all.btn_inserer;
pos_left = document.all.TdBarreBouton2.offsetLeft +
boutonInserer.offsetLeft;
pos_top = document.all.TdBarreBouton2.offsetTop +
boutonInserer.offsetTop;

But, the problem is if I move the button in the TD (id=TdButton1), I
MUST change the javascript code.
Is it possible to calculate the position of the button without
indicating the name of the TD in the javascript code ?

Thanks.

Mar 22 '07 #1
4 5022
You can use "parentNode" to get the parent TD of your button. E.g.

var boutonInserer = document.getElementById("btn_inserer");
var TdBarreBouton2 = boutonInserer.parentNode;

regards,

wp.

Mar 22 '07 #2
On Mar 22, 10:24 am, "wisestpotato" <wisestpot...@googlemail.com>
wrote:
You can use "parentNode" to get the parent TD of your button. E.g.

var boutonInserer = document.getElementById("btn_inserer");
var TdBarreBouton2 = boutonInserer.parentNode;

regards,

wp.
Thanks.

It's ok.

Mar 22 '07 #3
On Mar 22, 2:17 am, louv...@gmail.com wrote:
Hi,
I want to know the postion of the button.

My javascript code is :

boutonInserer = document.all.btn_inserer;
pos_left = document.all.TdBarreBouton2.offsetLeft +
boutonInserer.offsetLeft;
pos_top = document.all.TdBarreBouton2.offsetTop +
boutonInserer.offsetTop;
use offsetParent

Mar 22 '07 #4
On 22 Mar, 17:08, "scripts.contact" <scripts.cont...@gmail.comwrote:
On Mar 22, 2:17 am, louv...@gmail.com wrote:
Hi,
I want to know the postion of the button.
My javascript code is :
boutonInserer = document.all.btn_inserer;
pos_left = document.all.TdBarreBouton2.offsetLeft +
boutonInserer.offsetLeft;
pos_top = document.all.TdBarreBouton2.offsetTop +
boutonInserer.offsetTop;

use offsetParent
Be wary of offsetParent. It returns the parent element with respect to
positioning. So, if the current element is absolutely positioned, the
offsetParent may well be the document root node. If you want to be
sure of getting the parent node of the current element, irrespective
of any stylesheet positioning rules, then use parentNode instead.

wp.

Mar 26 '07 #5

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

Similar topics

1
by: Eshrath Ali Khan | last post by:
Hi, I have a requirement where I am transforming a XML into a html using an XSL. I need to create a object for the each and every occurrence of an element named "tgroup" in the xml. Also I need...
4
by: Ken Kast | last post by:
Here's my situation. I have a statically positioned table that has an image in a cell. I also have some layers, defined by absolute-positioned DIVs for some animation. Everything works until I...
14
by: Zenobia | last post by:
Hello folks, Is it possible to position an item within a <td> element? For instance see below. The table has multiple rows, one for each database record. Each row has 3 hrefs associated with it...
0
by: joeZ | last post by:
hi there! I'm just going crazy with this stuff I want to do I though was simple. I just want to locate an image (which is linkeable) below the bottom of a cell. I mean, if the cell is at...
2
by: ted | last post by:
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...
3
by: moondaddy | last post by:
I'm trying to create my first user control and its function is to replace the use of a frames page. I want to position it under the pages header menus and to the right of the pages contents menus....
3
by: jkarpago | last post by:
Hi: I need to find what control is in some position given. I mean, if I give the values left: 200px and top 300px I need to know what control in the page is in that position, or if there is not...
6
by: Gérard Talbot | last post by:
Hello fellow stylers, When trying this page http://www.gtalbot.org/BrowserBugsSection/PercentualRelativePositioning.html I get different rendered layouts with IE 6, IE 7 beta 2, Firefox...
5
by: Sunil Varma | last post by:
Hi, I've to write a function similar to this. int process(const vector<int>& vct,int key) { // Here I've to find the position of key in the vector and do some processing. }
4
by: HoangTuanSu | last post by:
I have just got a javascript code from my friend. I've modified it for my purpose but a problem happens. First, here's my code html <body> <table align="center" width="60%" height="100%"...
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: 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: 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:
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...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.