File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes how to get and set the position of an element in Java Script Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "how to get and set the position of an element in Java Script" Watch "how to get and set the position of an element in Java Script" New topic
Author

how to get and set the position of an element in Java Script

sandeep Kumar
Ranch Hand

Joined: Sep 19, 2007
Posts: 41
Hello All,

I want the functionality of getting the position of an element and also setting the postion of an element in Java Script. If any body has some working code snippetts, Please help me.

Thanks in Advance.


Regards,
Sandeep.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
To position:
Well you have CSS with position absolute or relative with top and left. You also have margins and padding to move it.

To read position:

Either you can read the CSS if it is positioned absolutely.

If not you have to do something like this:



You would call it:



Eric
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

if this is really important, then I recommend you check out jQuery and its Dimensions plugin which will take care of all these calculations for you.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
sandeep Kumar
Ranch Hand

Joined: Sep 19, 2007
Posts: 41
Hi Eric Pascarello and Bear Bibeault,

Thanks for your valuable suggestions.

Regards,
Sandeep.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to get and set the position of an element in Java Script