4

When I run following code:

        node = $('.period')
        alert(node.width() + ' ' + node.css('width'))

i get '0 144px'. How is that possible?

1
  • 5
    Please include the associated HTML Commented Jul 31, 2009 at 14:20

1 Answer 1

14

Maybe you're calling it on $(document).ready, and as width() Gets the current computed, pixel, width of the first matched element., it'd be 0 as it has not been rendered yet...
css('width') however reads from the css stylesheet, which would be already available.

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

4 Comments

I think this is right! I called it as a click and it computed correctly.
Does it apply to tab loading (I am using jquery ui tabs, not document ready) too? It seems so, but I would like to get sure.
I've actually never used jQuery UI. You could easily find out by trying to get the value at a later time (onClick for example).
If you want to be sure everything is loaded, you can use $(window).load

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.