1 line
1.4 KiB
JSON
1 line
1.4 KiB
JSON
{"name":"position","type":"method","title":".position()","deprecated":null,"removed":null,"desc":"Get the current coordinates of the first element in the set of matched elements, relative to the offset parent.","categories":["css","offset","manipulation/style-properties","version/1.2"],"entries":[{"return":"Object","signatures":{"added":"1.2"},"examples":{"desc":"Access the position of the second paragraph:","code":"\nvar p = $( \"p:first\" );\nvar position = p.position();\n$( \"p:last\" ).text( \"left: \" + position.left + \", top: \" + position.top );\n","css":"\n div {\n padding: 15px;\n }\n p {\n margin-left: 10px;\n }\n","html":"\n<div>\n <p>Hello</p>\n</div>\n<p></p>\n"},"longdesc":"\n <p>The <code>.position()</code> method allows us to retrieve the current position of an element <em>relative to the offset parent</em>. Contrast this with <code><a href=\"/offset/\">.offset()</a></code>, which retrieves the current position <em>relative to the document</em>. When positioning a new element near another one and within the same containing DOM element, <code>.position()</code> is the more useful.</p>\n <p>Returns an object containing the properties <code>top</code> and <code>left</code>.</p>\n <div class=\"warning\">\n <p><strong>Note:</strong> jQuery does not support getting the position coordinates of hidden elements or accounting for borders, margins, or padding set on the body element.</p>\n </div>\n "}]} |