.pos( [ New_Position ] ) - Relative positioning
Gets the relative position of an element with repect to it's immediate parent.
Sets a element to a particular position repective to it's parent if the new position is specified.
Parameters
Returns
Example 1
Find the relative position of div box. click on the box divs.
JS
HTML
CSS
$.domLoaded(function() { $.get(".box").on("click", function() { // Get the clicked box div var box = $.self(); // Get the position var po = box.pos(); // alert x and y fields alert(" x : " + po.x + " , y : " + po.y); }); });
Result
Example 2
Set fixed relative position of box div.
JS
HTML
CSS
$.domLoaded(function() { $.get("#btn1").on("click", function() { $.get("#box").pos({ x : 0, y : 0}); }); $.get("#btn2").on("click", function() { $.get("#box").pos({ x : 100, y : 100}); }); });
Result
Example 3
Set fixed relative position of box div.
JS
HTML
CSS
$.domLoaded(function() { $.get("#btn1").on("click", function() { $.get("#box").pos({ x : "+50"}); }); });
Result
| |||||||||||||||