Release:jQuery 1.2/CSS
From jQuery JavaScript Library
« Back to the full jQuery 1.2 Release Notes.
[edit]
.offset()
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.
Access the offset of the second paragraph.
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>
[edit]
.height() / .width() for document and window
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.
Get the width of the window viewport.
$(window).width();
Get the height of the document.
$(document).height();