Set element offset
Description
The following code shows how to set element offset.
Example
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
div {<!-- ww w. j ava 2 s.com-->
position: absolute;
left: 10px;
top: 50px;
width: 20px;
height: 20px;
background-color: green;
}
</style>
<script
src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$("div#box").click(function() {
var pos = $(this).offset({
top : 100,
left : 100
});
$("#watcher").text(pos.top + ":" + pos.left);
});
});
</script>
</head>
<body>
<p>
Where is the box? <span id="watcher"></span>
</p>
<div id="box"></div>
</body>
</html>