Showing posts with label dom. Show all posts
Showing posts with label dom. Show all posts

Wednesday, August 20, 2014

How to retrieve position X,Y of html element

How to define in what exactly position (X,Y) is the DOM element on page?
For example you have svg-area on your page and you need to adjust events on it, or 

1) For mouse events you can use event.clientX and event.clientY properties

2) When you use jQuery you can call position() method which will return object with 2 properties:

var position  = $(elem).position();
//position.left, position.top

3)  But if you have to make it in pure javascript you should use getBoundingClientRect() method on your DOM-element. It works like this:

var rect = document.getElementsById('svg').getBoundingClientRect();
//rect.top, rect.right, rect.bottom, rect.left

Thursday, August 23, 2012

document. Object properties


document.documentElement
References the root element of the document, in the case of HTML documents, the html element. This read only property is useful for accessing all elements on the page, such as the HEAD.

document.compatMode
The two possible values returned are "BackCompat" for Quirks and "CSS1Compat" for Strict.

document.documentMode 
IE8 only property


document.readyState
IE property. Supported in Opera 9+, Chrome, and FF 3.6+ as well.

Returns the loading status of the document. It returns one of the below 4 values:
 
uninitializedThe document hasn't started loading yet.
loadingThe document is loading.
interactiveThe document has loaded enough whereby user can interact with it.
completeThe document has fully loaded.

See also:
Defining Document Compatibility : http://msdn.microsoft.com/en-us/library/cc288325(VS.85).aspx