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

Get and set position and size of html nodes

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:

document.defaultView.getComputedStyle(element,null ).getPropertyValue("left")
/ getPropertyValue("width") ...

It will return "auto" in certain circumstances.

Using offsetLeft / offsetWidth to get the size and position seems also
not to be the best since values sometimes seems to be incorrect. Setting
control width to offsetWidth will causes the control to get larger than
before.

What is the best way to do this?

Is there any open source javascript "library" (js file) for this purpose?

yours
Benjamin
Apr 23 '07 #1
2 12904
On Apr 23, 11:41 am, Benjamin Kalytta <bkau...@web.dewrote:
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:

document.defaultView.getComputedStyle(element,null ).getPropertyValue("left")
/ getPropertyValue("width") ...

It will return "auto" in certain circumstances.

Using offsetLeft / offsetWidth to get the size and position seems also
not to be the best since values sometimes seems to be incorrect. Setting
control width to offsetWidth will causes the control to get larger than
before.

What is the best way to do this?

Is there any open source javascript "library" (js file) for this purpose?
Have a look at Matt Kruse's position library in his Javascript
Toolbox:

<URL: http://www.javascripttoolbox.com/lib...tion/index.php >
--
Rob

Apr 23 '07 #2
On Apr 22, 7:53 pm, RobG <r...@iinet.net.auwrote:
On Apr 23, 11:41 am, Benjamin Kalytta <bkau...@web.dewrote:
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:
document.defaultView.getComputedStyle(element,null ).getPropertyValue("left")
/ getPropertyValue("width") ...
It will return "auto" in certain circumstances.
Using offsetLeft / offsetWidth to get the size and position seems also
not to be the best since values sometimes seems to be incorrect. Setting
control width to offsetWidth will causes the control to get larger than
before.
What is the best way to do this?
Is there any open source javascript "library" (js file) for this purpose?

Have a look at Matt Kruse's position library in his Javascript
Toolbox:

<URL:http://www.javascripttoolbox.com/lib/objectposition/index.php>
Matt's is a good one for position reporting when the page is simple.
My tests showed it doesn't work in all combinations of nested elements
where some of the elements are scrolling, tables, frames, and other
oddities in a wide range of browsers (IE6, O8, S2, FF1.5, I believe).
I haven't seen a library that can do it all. Richard Cornford probably
has some of the most complete knowledge in this area and contests
repeatedly that such a library would be huge.

Peter

Apr 23 '07 #3

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

Similar topics

1
by: discomiller | last post by:
Mario Mueller: Hello *, radiobuttons belong to other radiobuttons by the "name="any_value"" attribut. Thats a fakt. I got the following XML:...
4
by: Matt | last post by:
When the user resize the browser, the "Frequently Used Link" and "Table 1" and "Table 2" will shift to the left hand side, but table position is unchanged. I really have no idea how to fix that. I...
5
by: jen_designs | last post by:
Is there a way to return the character position on a page? Not the x and y coordinates, but the number of characters on a page. For instance i have a html page with the following text: This is my...
7
by: Doc | last post by:
I've read in a couple of different places including the archives of this forum that html doesn't allow you to precisely dictate the position of an image, but I found this command (again in the...
1
by: dale zhang | last post by:
Hi, I have a web form page. it has gridlayout and a table at top like a template. When I have the literal or requiredfieldvalidator ErrorMsg displayed, they are all over the page. Is there...
6
by: meh | last post by:
I can figure out the total number of nodes in a given tree but what I'd like to know is what is the Selected Nodes relationship to the entire tree i.e This is node n out of nnn nodes. In most of...
8
by: Edward | last post by:
I used to do this all the time in HTML-table layouting. How do I do this in CSS? -------------------------------------------------- <table width="400px"> <tr> <td bgcolor="beige">one line of...
19
by: wmanzo | last post by:
I have a really professional conspiracy movie site and I use tons of layers and an external scroll bar assembly. I would like to put the various sections into MS Iframes and in order to clean up...
10
by: VividWeb | last post by:
Hi. I am relatively new to CSS and HTML but have a basic understanding of most things. One of my backgrounds is not positioning correctly in IE 7 or AOL. The background behind the content...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.