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

夙愿已清 提交于 2019-12-10 06:05:27

问题


When I run following code:

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

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


回答1:


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.



来源:https://stackoverflow.com/questions/1212790/jquery-why-csswidth-returns-different-value-than-width

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!