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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:27:41+00:00 2026-05-29T11:27:41+00:00

$(.div1).hide(); $(.div2).offset( $(.div1).offset() ).slideDown(); offset() seems to return the current cordinates of an element

  • 0
$(".div1").hide();
$(".div2").offset( $(".div1").offset() ).slideDown();

offset() seems to return the current cordinates of an element RELATIVE to the document. Fine. But when I try to use offset(value) to SET the cordinates of an element, it does it relative to the current position of the element, not the document.

In the example code, I tried to place div2 at the same position of div1.

Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html> 

<style>

div{margin-bottom: 2px; height: 70px}
.red{background-color: red}
.blue{background-color: blue}
.green{background-color: green}
.orange{background-color: orange}
.pink{background-color: pink}

.msg{background-color: skyblue; border: 1px solid black; border-radius: 5px; display: none}
</style>

<script type="text/javascript" src="/scripts/jquery-1.6.2.min.js"></script>
<script>
$(function(){   
    $(".msg").offset( $(".blue").offset() ).slideDown(); 

});
</script>

<body>

<div class="red"></div>
<div class="blue"></div>
<div class="green"></div>
<div class="orange"></div>
<div class="pink"></div>

<div class="msg">
    TEST
</div>

</body>

</html>
  • 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-29T11:27:44+00:00Added an answer on May 29, 2026 at 11:27 am

    The problem is because you are first hiding .div1, thereby making it’s offset inaccessible. Change your code around as below and it will work:

    $(".div2").offset( $(".div1").offset() ).slideDown();
    $(".div1").hide();
    

    I’ve tested this works in jsFiddle, but can’t link to it at the moment as they’re changing their hosting.

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

Sidebar

Related Questions

it works fine for one div (function($) { $(document).ready(function(){ $('#div1').hide(); $('a.plus').click(function(){ $('#div1').slideToggle(); $(this).toggleClass(minus_icon); return
$('#div1').children('div:last').css('border-bottom', ''); $('#div2').focus(); I am using above and it works fine with ie but
Is it possible to somehow shorten this code: var i=GetStringFromServer('/url'); if(i){ $('#Div1').hide(); $('#Div2').show(); }
Given the following HTML example... <div id='div1'>div one</div> <div id='div2'>div two</div> ...I found that
I have 3 divs. When you click HIDE on divChaptersHide (div1) it will be
This code works fine in IE8/7 and Firefox... But in Google Chrome i got
I have a group of IDs with similar names (ex: div1, div2, div3) that
I have a wrapper div1, with div2 inside which contains a string. When i
I have two divs: div1 and div2 . Maintaining the original css styles applied
I am working on a project in which I have two DIVs (DIV1, DIV2),

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.