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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:27:25+00:00 2026-05-13T18:27:25+00:00

I just realised there is a difference between <foo>.css(‘marginTop’) (which I thought is the

  • 0

I just realised there is a difference between

<foo>.css('marginTop')

(which I thought is the standard jquery-notation) and

<foo>.css('margin-top')

(which I thought was non-standard).

If has margin-top: 3em; (for example), the first notation gives me 3em, the second notation gives me 48px (which is 3em in Pixels).
I like this behaviour but I could not find anything about it in the API (or am I blind?)

Why is this the case and where can I find information about it?

P.S.: Just to be precise: of course other attributes but margin-top work aswell…

Thank you!

  • 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-13T18:27:26+00:00Added an answer on May 13, 2026 at 6:27 pm

    The doc says “jQuery can equally interpret the CSS and DOM formatting of multiple-word properties”, but in reality it is doing that through rough and ready hacks which don’t always behave predictably.

    In particular, if you supply a DOM-style camelCaseName, it will first try to access the inline style declaration as style.camelCaseName. Then if that fails (typically because the style was not set inline), it falls back to trying getComputedStyle with the camelCaseName converted to hyphen-separated-name(*). The computed style is not the same thing as the declared style: the browser can resolve various relative declarations in a computed style, such as converting lengths to pixel units.

    However, the reverse does not hold! If you supply a CSS-style hyphen-separated-name, it jumps straight to the computed style(*) code without trying to convert to camelCaseName and look at the inline style.

    I don’t think I’d want to rely on this behaviour… it smells a little bit buggy to me. If you can keep the inline style declaration off the element you want to measure, you should be able to ensure you always get the computed style back regardless of which name type you use. But then again, jQuery doesn’t give you that as a documented promise. Such is the nature of trying to hide a complicated model behind a seemingly-simple “Do What I Mean” interface.

    (*): except in IE where there is no getComputedStyle function, so it falls back to a weird and fragile mix of currentStyle, runtimeStyle and document alteration to try to get a computed style out.

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

Sidebar

Related Questions

I just realised that Office 2007 now shows multiple pages per default. I can
Have had to write my first proper multithreaded coded recently, and realised just how
I just realized that in some place in my code I have the return
I just realized from an article in CACM that Doxygen works with Java (and
So I made some timers for a quiz. The thing is, I just realized
Just what the title says, I need to change the password for an existing
Just looking for the first step basic solution here that keeps the honest people
just a quick question: I am a CS undergrad and have only had experience
Just bought a 2.4GHz Intel Core 2 Duo iMac with 2GB of memory and
Just getting my head around Ruby metaprogramming. The mixin/modules always manage to confuse me.

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.