Difference between revisions of "Jquery element position"

From John Freier
Jump to: navigation, search
 
Line 10: Line 10:
 
Top
 
Top
 
  $(this).position().top
 
  $(this).position().top
 +
 +
 +
== Set Position ==
 +
To set the position of an element, you will want to make the position absolute, and then set the css values.
 +
 +
Position Absolute
 +
position:absolute;
 +
 +
Left
 +
$(this).css('left', 100);
 +
 +
Top
 +
$(this).css('top', 100);

Latest revision as of 17:09, 5 October 2011

This section is all about how to position elements on a page.


Get Position

To get the position, jquery has a method on it with two attributes.

Left

$(this).position().left

Top

$(this).position().top


Set Position

To set the position of an element, you will want to make the position absolute, and then set the css values.

Position Absolute

position:absolute;

Left

$(this).css('left', 100);

Top

$(this).css('top', 100);