« Back to the full jQuery 1.2 Release Notes.
Brought over from the Dimensions plugin, the .offset() method allows you to find the offset of the element (as 'top' and 'left') from the top-left corner of the document.
var p = $("p:last"); var offset = p.offset(); p.html( "left: " + offset.left + ", top: " + offset.top );
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(){
var p = $("p:last");
var offset = p.offset();
p.html( "left: " + offset.left + ", top: " + offset.top );
});
</script>
</head>
<body>
<p>Hello</p><p>2nd Paragraph</p>
</body>
</html>
The .height() and .width() now work on the document and window objects; allowing to get the height and width of the document body and the window viewport.
$(window).width();
$(document).height();