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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:20:37+00:00 2026-05-28T18:20:37+00:00

Hi I have some elements like these: <div id=one>content</div> <div id=two>content</div> and a corrispondent

  • 0

Hi I have some elements like these:

<div id="one">content</div>
<div id="two">content</div>

and a corrispondent number of elements (without any parent, they are just after the body tag) that have:

position: absolute;

and with an id like that:

id="helper-one" refers to id="one"

Now i want to place the second group of elements exactly at the middle (vertical and horizontal) of referred elements, how can i do that?

I’ve tried with offset:

    var one_offset = $("#one").offset();

    $("#helper-one").offset({ top: one_offset.top, right: one_offset.right, left:one_offset.left, bottom: one_offset.bottom})

but it set position only for top and left positionating the helper at the top-left corner of the element and not at its center

  • 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-28T18:20:39+00:00Added an answer on May 28, 2026 at 6:20 pm
    jQuery.fn.center = function (obj) {
      var loc = obj.offset();
      this.css("top",(obj.outerHeight() - this.outerHeight()) / 2 + loc.top + 'px');
      this.css("left",(obj.outerWidth() - this.outerWidth())  / 2 + loc.left+ 'px');
      return this;
    }
    

    Call as $("#helper-one").center($("#one"));

    ps: you may even skip obj argument by parsing the id of the original element

    jQuery.fn.center = function () {
      var obj = $('#' + this.attr('id').split('-')[1]), loc = obj.offset();
      this.css("top",(obj.outerHeight() - this.outerHeight()) / 2 + loc.top + 'px');
      this.css("left",(obj.outerWidth() - this.outerWidth())  / 2 + loc.left+ 'px');
      return this;
    }
    
    $(document).ready(function(){
       $("#helper-one").center();       
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two LinkedLists, I'd like to move all elements which match some criteria
I have some elements on a page which are draggable. These same elements have
I use NSXMLParser but i have some elements that they have the same name.
I have some page elements which are meant to appear in a two column
I have a slider-like widget which is basically, a div of sub-divs containing some
In my HTML there are a lot of elements. Some div elements have an
I have a div. Inside that div I have multiple elements. Some elements have
I have some some rows of image thumbs inside anchors inside a div, one
I have several div elements like this: <div class=newsContainer> <div class=deleteBoxIcon> <img alt=Delete src=close_mark.png>
So, I was wondering about the following: I have some main content div and

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.