Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > find position of a element in a table

Reply
Thread Tools

find position of a element in a table

 
 
louvino@gmail.com
Guest
Posts: n/a
 
      03-22-2007
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.

 
Reply With Quote
 
 
 
 
wisestpotato
Guest
Posts: n/a
 
      03-22-2007
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.

 
Reply With Quote
 
 
 
 
louvino@gmail.com
Guest
Posts: n/a
 
      03-22-2007
On Mar 22, 10:24 am, "wisestpotato" <(E-Mail Removed)>
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.

 
Reply With Quote
 
scripts.contact
Guest
Posts: n/a
 
      03-22-2007
On Mar 22, 2:17 am, (E-Mail Removed) 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

 
Reply With Quote
 
wisestpotato
Guest
Posts: n/a
 
      03-26-2007
On 22 Mar, 17:08, "scripts.contact" <(E-Mail Removed)> wrote:
> On Mar 22, 2:17 am, (E-Mail Removed) 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.

 
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
Find position of element using binary_search Angus C++ 10 03-11-2011 12:38 AM
Position an element dynamically on top of an existing element Konrad Hammerer HTML 14 02-07-2008 11:34 PM
ColGroup for a table element gets lost when the table element is made visible/invisible TS ASP .Net 5 08-16-2007 11:26 AM
How to find out the position of a element in the XML Document Eshrath Ali Khan XML 1 11-09-2004 07:30 PM
CSS and javascript, find absolute position of element Knut Javascript 1 10-15-2004 02:27 AM



Advertisments