AJAX Example Getting Coordination Parameters of a HTML Element with Javascript

This is an example of how you can get the coordination parameters of a HTML element on a web page.

var tgt = document.getElementById('tgtId');
if (tgt.offsetParent.localName == 'body') {
  // offsets are relative to body. check these:
  x=tgt.offsetLeft; y=tgt.offsetTop; 
  w=tgt.offsetWidth; h=tgt.offsetHehght;
} else {
  // error.

For computed style, you can use window.getComputedStyle(tgtelem, null) to get the full style node. Inspect inside to see what you’ll see.


About minghuasweblog

a long time coder
This entry was posted in AJAX and Webapp, All and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s