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

How to get position of elements in Div

Hi,

I am tying to do a editable dropdown. Example of the code snippet is as follows:

Expand|Select|Wrap|Line Numbers
  1. textbox.style.width = listbox.offsetWidth - downButtonWidth;
  2. listbox.style.position = 'absolute';
  3. listbox.style.clip = 'rect(auto, auto, auto, ' + textbox.style.width + ')';
  4.  
  5. listbox.style.left = textbox.offsetLeft;
  6. listbox.style.top = textbox.offsetTop;    
  7. var obj = textbox;
  8. while ((obj = obj.offsetParent) != null)
  9. {
  10.        listbox.style.left = listbox.style.pixelLeft + obj.offsetLeft;
  11.        listbox.style.top = listbox.style.pixelTop + obj.offsetTop;
  12. }
  13.  
This piece of code works perfectly fine when I place my textbox and list in a div tag without any height specified.

However, when I specify height=60% in my div tag, the whole code fails. I will end up with a floating listbox arrow that does not align with my textbox.

May I know how can I rectified this problem. Thank you very much.
Apr 23 '07 #1
1 4900
acoder
16,027 Expert Mod 8TB
To get the current position, see this link. When setting the position, don't forget the units, e.g. "px". pixelLeft/Top are not supported by all browsers. To align, get the current position of the textbox and set the arrow the same top and left to left+width.
Jun 7 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

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...
6
by: Harald Kirsch | last post by:
In the W3C document about CSS2, I read at http://www.w3.org/TR/REC-CSS2/visuren.html#choose-position the following: absolute The box's position (and possibly size) is specified with the...
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...
3
by: Matthias Lohrer | last post by:
Hi, my XML-Document hat this structure <book> <section> <para /> <para /> </section> <section> <para />
4
by: Guy | last post by:
Hi, I read an XML file to an XMLDocument and iterate through its nodes. How do I get the XPath position (index) of a certain element? For example If I on the second "b" node I want to get "2": ...
3
by: engartte | last post by:
Hi all, Let consider the following solution: #include <stdio.h> int main () { int a, temp; int i; for(i=0; i<10; i++){
2
by: petermichaux | last post by:
Hi, It seems like determining element position in a web page is a difficult task. In the position reporting source code I've looked at there are special fixes for at least some versions of...
2
by: Benjamin Kalytta | last post by:
Hi there, How do I get and set position and size of a html node (certain elements)? Following will not work for non absolute elements: ...
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: 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...
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
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:
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...

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.