.position()S2C Home « Attributes & Properties « .position()

First element current coordinates retrieval.

Description

The .position() method is used to retrieve the current coordinates from the first element within the matched set, relative to the offset parent.

  • Use the .offset() method if you wish to retrieve the current coordinates relative to the document , rather than relative to the offset parent.
  • You cannot use the .position() method on hidden elements.

Syntax

Signature Description
.position() Retrieve the current coordinates from the first element within the matched set, relative to the offset parent.

Parameters

None.

Return

An Object object containing the properties top and left.

.position() ExampleTop

Retrieve the current coordinates from the first element within the matched set, relative to the offset parent.

In the example below when we alert the offset position of the following image with the id of 'curry'. The offset parent in this case is the main content of the page.

a picture of curry


$(function(){
  $('#btn25').on('click', function() {
    alert('The offset coordinates of the of the above image are: ' 
           + JSON.stringify($('#curry').position()) + '.'); 
  });
});

Press the button below to action the above code: