.position( options )Returns: jQueryversion added: 1.8

Description: Position an element relative to another.

The jQuery UI .position() method allows you to position an element relative to the window, document, another element, or the cursor/mouse, without worrying about offset parents.

Note: jQuery UI does not support positioning hidden elements.

This is a standalone jQuery plugin and has no dependencies on other jQuery UI components.

This plugin extends jQuery's built-in .position() method. If jQuery UI is not loaded, calling the .position() method may not fail directly, as the method still exists. However, the expected behavior will not occur.

Example:

A simple jQuery UI Position example.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>position demo</title>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css">
    <style>
    .positionDiv {
        position: absolute;
        width: 75px;
        height: 75px;
        background: green;
    }
    </style>
    <script src="http://code.jquery.com/jquery-1.8.3.js"></script>
    <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
</head>
<body>
 
<div id="targetElement">
    <div class="positionDiv" id="position1"></div>
    <div class="positionDiv" id="position2"></div>
    <div class="positionDiv" id="position3"></div>
    <div class="positionDiv" id="position4"></div>
</div>
 
<script>
$( "#position1" ).position({
    my: "center",
    at: "center",
    of: "#targetElement"
});
 
$( "#position2" ).position({
    my: "left top",
    at: "left top",
    of: "#targetElement"
});
 
$( "#position3" ).position({
    my: "right center",
    at: "right bottom",
    of: "#targetElement"
});
 
$( document ).mousemove(function( event ) {
    $( "#position4" ).position({
        my: "left+3 bottom-3",
        of: event,
        collision: "fit"
    });
});
</script>
 
</body>
</html>

Demo: