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

  • SEARCH
  • Home
  • 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 9009629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:15:02+00:00 2026-06-16T02:15:02+00:00

How do I find out the absolute position of an element on the current

  • 0

How do I find out the absolute position of an element on the current visible screen (viewport) using jQuery?

I am having position:relative, so offset() will only give the offset within the parent.

I have hierarchical divs, so $("#me").parent().offset() + $("#me").offset() doesn’t help either.

I need the position in the window, not the document, so when the document is scrolled, the value should change.

I know I could add up all the parent offsets, but I want a cleaner solution.

var top = $("#map").offset().top + 
    $("#map").parent().offset().top + 
    $("#map").parent().parent().offset().top +
    $("#map").parent().parent().parent().offset().top;

Any ideas?

Update:
I need to get the exact gap in pixels between the top of my div and the top of the document, including padding/margins/offset?

My code:

HTML

<div id="map_frame" class="frame" hidden="hidden">
    <div id="map_wrapper">
        <div id="map"></div>
    </div>
</div>

CSS

#map_frame{
    border:1px solid #800008;
}

#map_wrapper {
    position:relative;
    left:2%;
    top:1%;
    width:95%;
    max-height:80%;
    display:block;
}

#map {
    position:relative;
    height:100%;
    width:100%;
    display:block;
    border:3px solid #fff;
}

jQuery to resize the map to fill the screen*

var t = $("#map").offset().top + 
    $("#map").parent().offset().top + 
    $("#map").parent().parent().offset().top + 
    $("#map").parent().parent().parent().offset().top;

$("#map").height($(window).height() - t - ($(window).height() * 8 / 100));

Thanks…

  • 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-06-16T02:15:04+00:00Added an answer on June 16, 2026 at 2:15 am

    See .offset() here in the jQuery doc. It gives the position relative to the document, not to the parent. You perhaps have .offset() and .position() confused. If you want the position in the window instead of the position in the document, you can subtract off the .scrollTop() and .scrollLeft() values to account for the scrolled position.

    Here’s an excerpt from the doc:

    The .offset() method allows us to retrieve the current position of an
    element relative to the document. Contrast this with .position(),
    which retrieves the current position relative to the offset parent.
    When positioning a new element on top of an existing one for global
    manipulation (in particular, for implementing drag-and-drop),
    .offset() is the more useful.

    To combine these:

    var offset = $("selector").offset();
    var posY = offset.top - $(window).scrollTop();
    var posX = offset.left - $(window).scrollLeft(); 
    

    You can try it here (scroll to see the numbers change): http://jsfiddle.net/jfriend00/hxRPQ/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to find out the position of an element which is in iframe.
To find out the start command for mysqld (using a mac) I can do:
I am trying to find out how to write an SQL statement that will
I will appreciate if somebody could help me to find how to solve out
I am trying to find out how to get a jQuery script to work
With jQuery how do i find out if div one is over div two
Find out the time complexity (Big Oh Bound) of the recurrence T(n) = T(⌊n⌋)
I find out how to replace the busy cursor here: http://livedocs.adobe.com/flex/3/html/cursormgr_3.html However, how do
To find out if some important functions were removed (and without doing a lot
I recently find out that wpf handles INotifyPropertyChanged in two different ways. I just

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.