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

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

    var elH = someElement.height();           // 200
    

    .height() returns a Number, while

    var elH = someElement.css("height");      // "200px"
    

    above jQuery accesses the element's style property like JS would in:

    var height = someDOMelement.style.height; // "200px"
    

    returning a String value in px.

提交回复
热议问题