Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

jquery

css

width

When I run following code:

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

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

like image 927
gruszczy Avatar asked Dec 10 '22 19:12

gruszczy


1 Answers

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.

like image 189
fresskoma Avatar answered Jan 11 '23 22:01

fresskoma