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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:59:32+00:00 2026-06-18T11:59:32+00:00

When you set an element’s offset with jQuery.offset({coords}) it also sets the CSS property

  • 0

When you set an element’s offset with jQuery.offset({coords}) it also sets the CSS property position to absolute.

I have a div, however, that I set to position: fixed in my CSS, and I want it to remain that way, even after setting the offset of the element with jQuery.

Now, I’m sure I can probably set the offset, then set position: fixed again, but I was wondering if there is a way I can tell jQuery to set the position to fixed instead of absolute when it sets offset.

HTML

<div class="searchResults">
    ...
</div>

CSS

DIV.searchResults {
    position: fixed;
    padding: 20px;
    background-color: red;
    z-index: 501;
}

jQuery

$("DIV.searchResults").offset({left: 0, top: 0});

Rendered HTML

<div class="searchResults" style="position: absolute; top: 0px; left: 0px;">
    ...
</div>

Obviously, since jQuery is setting the position in the style, it will trump the value of my CSS class. So I need a way to tell jQuery to set position to fixed instead of absolute, or tell it to set the offset without setting the value of the CSS property position.

  • 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-18T11:59:33+00:00Added an answer on June 18, 2026 at 11:59 am

    As I commented above, in your case all you need is to modify the CSS for top and left like this:

    $("DIV.searchResults").css({left: 0, top: 0});
    

    Because the $.offset setter method only manipulates the left, top and position values to make the element relative to the page (from static to relative, and from fixed to absolute). Since you want it position fixed, set the values directly.

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

Sidebar

Related Questions

I have seen people set an element's style to: element{ position:absolute; left:-10000px; } rather
I would like to set an element's position to absolute and have a margin-bottom
I want to set an element whose position is absolute at center , means
Is z-index only used when you set an element's position to absolute or it
I have an img element set next to a div. I have tried a
Inside the div element set within variable called $target I have elements with single
Inside the div element set within variable called $target I have elements with single
i have to ecxlude the parent of a clicked element in a jQuery set
I have a video element set to 100% width in a container div. That
Using javascript - we can set the element relative position such as object.style.position=absolute||fixed||relative But,on

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.