.css(‘width’) and .css(‘height’) versus .width() and .height()

前端 未结 10 1008
旧时难觅i
旧时难觅i 2021-01-07 19:44

Guys I\'ve been asking around and nobody can really tell me the benefits of using .css(‘width’) and .css(‘height’) rather than .width()

10条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-07 20:23

    From the .height() documentation -

    The difference between .css('height') and .height() is that the latter returns a unit-less pixel value (for example, 400) while the former returns a value with units intact (for example, 400px). The .height() method is recommended when an element's height needs to be used in a mathematical calculation.

    If you need to use height in a calculation get the value with .height().

提交回复
热议问题