Get the position of an element with .position()

.position()


Description: Get the position of an element (relative to its parent element)


Example:

<!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>position demo</title>
      <script src="http://code.bitsycode.com/bitsycode-latest.min.js"></script>
    </head>
    <body>
      
      <div class="mycontainer">This is my container</div>
      <div class="result"></div>
      
      <script>
         
         bitsyCode.ready(function(){
            var position = bitsyCode(".mycontainer").position();
            bitsyCode(".result").append("Top: " + position.top + "<br /> Left: "+ position.left);
         })
         
      </script>
     
    </body>
    </html>

Preview:

This is my container
  • Usage

    • How to use:

      The .position() method will return the elements position (relative to its parent element).

    • USAGE:

      bitsyCode(".mycontainer").position();
  • Options

    • What options are there:

      There are no options for this method.

  • Returns

    • Return: { top:0, left:0 }   // Returns an object with the top and left position of the element.
Share