gruszczy
gruszczy

Reputation: 42208

jquery: why css('width') returns different value than width()

When I run following code:

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

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

Upvotes: 4

Views: 8615

Answers (1)

fresskoma
fresskoma

Reputation: 25791

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.

Upvotes: 14

Related Questions