Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1077601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:35:57+00:00 2026-05-16T21:35:57+00:00

Given an HTML DOM ID, how to get an element’s position relative to the

  • 0

Given an HTML DOM ID, how to get an element’s position relative to the window in JavaScript/JQuery? This is not the same as relative to the document nor offset parent since the element may be inside an iframe or some other elements. I need to get the screen location of the element’s rectangle (as in position and dimension) as it is currently being displayed. Negative values are acceptable if the element is currently off-screen (have been scrolled off).

This is for an iPad (WebKit / WebView) application. Whenever the user taps on a special link in an UIWebView, I am supposed to open a popover view that displays further information about the link. The popover view needs to display an arrow that points back to the part of the screen that invokes it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T21:35:57+00:00Added an answer on May 16, 2026 at 9:35 pm

    Initially, Grab the .offset position of the element and calculate its relative position with respect to window

    Refer :
    1. offset
    2. scroll
    3. scrollTop

    You can give it a try at this fiddle

    Following few lines of code explains how this can be solved

    when .scroll event is performed, we calculate the relative position of the element with respect to window object

    $(window).scroll(function () {
        console.log(eTop - $(window).scrollTop());
    });
    

    when scroll is performed in browser, we call the above event handler function

    code snippet


    function log(txt) {
      $("#log").html("location : <b>" + txt + "</b> px")
    }
    
    $(function() {
      var eTop = $('#element').offset().top; //get the offset top of the element
      log(eTop - $(window).scrollTop()); //position of the ele w.r.t window
    
      $(window).scroll(function() { //when window is scrolled
        log(eTop - $(window).scrollTop());
      });
    });
    #element {
      margin: 140px;
      text-align: center;
      padding: 5px;
      width: 200px;
      height: 200px;
      border: 1px solid #0099f9;
      border-radius: 3px;
      background: #444;
      color: #0099d9;
      opacity: 0.6;
    }
    #log {
      position: fixed;
      top: 40px;
      left: 40px;
      color: #333;
    }
    #scroll {
      position: fixed;
      bottom: 10px;
      right: 10px;
      border: 1px solid #000;
      border-radius: 2px;
      padding: 5px;
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div id="log"></div>
    
    <div id="element">Hello
      <hr>World</div>
    <div id="scroll">Scroll Down</div>
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.