Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 60800
    
  65

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
 
Similar Threads
javascript css issue
Adding jquery to a page
Textbox value removal
Auto complete in JSF
place div element in lower left corner of browser using jQuery