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

前端 未结 10 962
旧时难觅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:16

    By now people should know that one should be used for maths, and the other shouldn't...

    Or should it?

    I did a little speed test on the various options and according to my findings:

    1. It is faster to grab the width with .css
    2. It is faster to set the width with .width

    So in other words, to do a grab something and set another, you probably should:

    $('#element1').width(parseInt($('#element2').css('width'), 10));
    

提交回复
热议问题