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 6808877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:00:36+00:00 2026-05-26T20:00:36+00:00

I’m working on code that programmatically positions a div to give the appearance of

  • 0

I’m working on code that programmatically positions a div to give the appearance of scrolling. All works fine when using Firefox and Internet Explorer (believe it or not). However, I’m getting bogus values from webkit browsers (Chrome/Safari). It appears to have something to do with whether an element has content. I’m calculating the position of an empty anchor element. Webkit seems to get it right only when the element has visible content. So, I could work around this by having some content in my anchor. However, that messes up my layout and feels like a kludge. Also, I’d like to log a bug, if that is indeed what I’m dealing with. Below is a sample document to illustrate the issue. Open it in the different browsers to see what I mean. Much thanks in advance! 🙂

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <title>What's Up with Webkit Anchor offset()?</title>
    <meta http-equiv="Content-type" content="text/html; charset=UTF-8">
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js" ></script>
    <script type="text/javascript">
        var offsetAlert = function(calledBy){
            var anchor = jQuery("a#anchor");
            var span = jQuery("span#test");
            var subheading = jQuery("span#targetSubHeading");
            if (anchor.length == 1 && span.length == 1 && subheading.length == 1)
            {
                alert("offsetAlert(calledBy=["+calledBy+"])\n\tanchor.offset().top=["+anchor.offset().top+"]\n\nspan.offset().top=["+span.offset().top+"]\n\nsubheading.offset().top=["+subheading.offset().top+"]");
            }

        };

        $(document).ready(function (){offsetAlert("jQuery.ready");});
    </script>
</head>
<body style="background-color:#c6cbd1; margin:0px; padding:0px; border:none;" onload="javascript:offsetAlert('body.onload');">
    <div>
        <a name="top"></a><h2>Heading</h2>
        This is the phenomemaly interesting text.
        <br ><br >This is the phenomemaly interesting text.
        <br ><br >This is the phenomemaly interesting text.
        <br ><br >Internal Links: <a href="#a1">Sub-heading 1</a>, <a href="#a2">Sub-heading 2</a>, <a href="#a3">Sub-heading 3</a>, <a href="#anchor">Target Sub-heading</a>
        <br ><br ><b><a id="a1"></a>Sub-heading 1</b>
        <br >This is the phenomemaly interesting text. 
        <br><a href="#top">top</a>
        <br ><br ><a id="a2"></a><b>Sub-heading 2</b>
        <br >This is the phenomemaly interesting text.
        <br><a href="#top">top</a>
        <br ><br ><b><a id="a3"></a>Sub-heading 3</b>
        <br >This is the phenomemaly interesting text.
        <br><a href="#top">top</a>
        <br ><br ><span class="anchor" id="test"><a id="anchor"></a></span><span id="targetSubHeading" style="font-weight:bold;">Target Sub-heading</span>
        <br >This is the phenomemaly interesting text.
        <br><a href="#top">top</a>
    </div>
</body>
</html>

Okay, here’s an update. Thanks to Charles for the answer below. I updated my example to function to illustrate both the problem and the workaround I came up with based on Charles’ answer. This seems to work, but I’m still wondering if I should report this is a bug.

var offsetAlert = function(calledBy){
    var anchor = jQuery("a#anchor");
    var subheading = jQuery("span#targetSubHeading");
    var displayCss = anchor.css("display");
    anchor.css("display", "block");
    var alteredOffset = anchor.offset();
    anchor.css("display", (displayCss ? displayCss : ""));
    if (anchor.length == 1 && subheading.length == 1)
    {
        alert("displayCss=["+displayCss+"]\nalteredOffset.top=["+alteredOffset.top+"]\noffsetAlert(calledBy=["+calledBy+"])\n\tanchor.offset().top=["+anchor.offset().top+"]\n\nsubheading.offset().top=["+subheading.offset().top+"]");
    }
};

Thanks!


Here’s hopefully the last update. I checked Webkit and didn’t find this bug. So I added a new bug and a link to this question. Hopefully, this will get some attention and eventually get fixed. Here’s the link: http://bugs.webkit.org/show_bug.cgi?id=72524

BTW – I briefly had on here a link to an existing bug, but it turned out that it was for offsetHeight and not offsetTop.

  • 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-26T20:00:37+00:00Added an answer on May 26, 2026 at 8:00 pm

    From what I can see, this affects any inline-element without content. Changing the span-element to any block element or adding display: block; to the span-tag gives me the same values as in IE.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build

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.