Why does jQuery.css('width') return different values in different browsers?

前端 未结 2 1980
一个人的身影
一个人的身影 2021-01-19 14:40

I\'ve written some jQuery code that reads the width of the columns in a table and applies them to another table.

On my page, there is a TABLE like this:



        
2条回答
  •  悲&欢浪女
    2021-01-19 15:23

    I faced the same problem trying to detect the width of the body and load specific scripts and I worked around it this way. May help you as well.

    $('body,html').css({'overflow':'hidden'});
    var width = $('body').width();
    $('body,html').css({'overflow':''});
    

    this gives a consistent value in all major browsers

    `

提交回复
热议问题