title: Code to find absolute position of an element of DOM in Java
body: <p>I am working on a project in <strong>Java</strong>.</p>
  
  <p>In this project, I have to find  absolute position of an element of DOM. But I don't know how to do this.</p>
  
  <p>I searched on net, I found the same for Javascript. I found this from <a href="http://www.kirupa.com/html5/get_element_position_using_javascript.htm" rel="nofollow">here</a>.</p>
  
  <p><strong>Code is this</strong>, </p>
  
  <pre><code>function getPosition(element) {
      var xPosition = 0;
      var yPosition = 0;
  
      while(element) {
          xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
          yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
          element = element.offsetParent;
      }
      return { x: xPosition, y: yPosition };
  } 
  </code></pre>
  
  <p>When I try to write this code in Java, <strong>offsetLeft, offsetTop</strong> variable is not found. Can you tell me, how can I write this code in Java? </p>
  
  <p><strong>Edit No. 1</strong></p>
  
  <p>Is there any method using <strong>Jsoup</strong> for the same?</p>