Checking an object's properties
If you haven't already done so, read the introduction before continuing.
The string passed to check() consists of a selector and a property. If the selector is an id, and the property a CSS property, the function can return the value for that id. Well, sometimes. I want to know the background-color of an object with the id "target_div", so:
var bg_colour = check (‘target_div backgroundColor’);
The function will return a value if:
- the background-color has been set or reset using JavaScript, or
- the background-color was set inline
If it was specified in a style section in the head of the document, or in an external style sheet, no value will be returned. The exceptions to this are the top, left, height and width properties of an object. These are always available using check() [1].
The function can also return the src of an image:
var image_src = check (‘target_image src’);
This can be useful if you want to toggle two images: check the src of the current image, then set it to the other one.
Finding the dimensions of screen and window
The function check() can return the dimensions of the screen or window [2], for example:
var winw = check (‘window width’);
var scrnh = check (‘screen height’);
Notes:
1. The function uses the offset methods (offsetTop, offsetLeft, offsetHeight, offsetWidth). Note that the first two return the position of the object relative to its parent - which may or may not be the window.
2.The window-checking function is based on one written by Mark 'Tarquin' Wilton-Jones. His excellent article explains in detail the problems associated with checking the browser window.