1

After several attempts using width(), outerWidth() and css("width) I discovered that all of these methods return a calculated value (in my case always different from the original value), so how can I read the value I set for element width in my css?

6
  • 1
    it should always be same, unless there is some padding set. so get the value of padding aswell Commented Jun 24, 2013 at 14:00
  • infact, css("width") should work Commented Jun 24, 2013 at 14:01
  • @Rhea Unfortunately the value is not the same of css: bugs.jquery.com/ticket/14022 Commented Jun 24, 2013 at 14:05
  • Sounds like you have an element inside you original element that may be expanding the width beyond what you have set in your stylesheet and all those answers, don't they read the question? Commented Jun 24, 2013 at 14:14
  • 2
    Provide a jsfiddle to test it or at least relevant html code Commented Jun 24, 2013 at 14:14

1 Answer 1

1

Try OuterWidth

$('#target').outerWidth(true);

the padding and border are included in the calculation; if you pass true, the margin is also included.

Sign up to request clarification or add additional context in comments.

1 Comment

This is not working for me. It returns a greater value also specifying includeMargin=true. So I'd like to read the value directly from my CSS...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.