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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:50:46+00:00 2026-06-15T14:50:46+00:00

My CSS rule looks like this: #my-div{ display: none; position: absolute; left: -160px; bottom:

  • 0

My CSS rule looks like this:

#my-div{
    display: none;
    position: absolute;
    left: -160px;
    bottom: -150px;
}

I’m trying to get value of the left-property like this:

  • document.getElementById('my-div').style.left
  • document.getElementById('my-div').offsetLeft

The problem is that both return null. Where is the problem?

  • 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-15T14:50:46+00:00Added an answer on June 15, 2026 at 2:50 pm

    The problem is that someElement.style.left only work if you have inline style. Since you apply your styling through a stylesheet, you will not be able to fetch the value the way you expect.

    You have a couple of other approaches you could take to get the value through JavaScript:

    window.getComputedStyle:

    It is possible to get the computed style of an element using window.getComputedStyle, the problem is that it has quite limited support (IE9+). If you still want to use it you could wrap it up in a function to make it a bit easier to get each property:

    function getCssProperty(elmId, property){
       var elem = document.getElementById(elmId);
       return window.getComputedStyle(elem,null).getPropertyValue(property);
    }
    // You could now get your value like
    var left = getCssProperty("my-div", "left");
    

    Working example

    jQuery (or some other library):

    Another option would be to use a JavaScript library like jQuery (or whatever you prefer), which will provide you with a cross-browser solution to get the value.

    With jQuery you could use the .css() method to read the CSS-property of the element.

    $(function () {
      var left = $("#my-div").css("left");
    });
    

    Working example
    ​

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

Sidebar

Related Questions

I have a css rule like this: .foo:active { background-position: 0px -382px; } .foo
I have a CSS rule like this: background: #fff url('/assets/img/file.png'); It is compiling to:
Lets say I wrote a simple CSS rule like this: .star_10 { background: url(stars.png)
I have a css rule like this in my css file: .Island_VerticalMenu:first-child { width:
I am finding I'm writing a lot of code that looks like this: <div
CSS iframe { display: none; } JS $('iframe').load(function() { $('iframe').fadeIn('slow'); }); HTML <a href=http://example.com
I'm trying to write a function that will receive a CSS Rule to update
I have this CSS rule: #panelSeparator .active { background: #fff url(../img/vgrabber.gif) no-repeat center; opacity:
Here is my css rule together with the markup: <div style = height:100%;> <div
My current .htaccess looks like this: RewriteEngine On # RewriteCond %{REQUEST_URI} !^/_project RewriteCond %{REQUEST_FILENAME}

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.