Epik Epik - 3 months ago 6x
Javascript Question

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

Guys I've been asking around and nobody can really tell me the benefits of using

rather than

I know that they both return the offset dimensions, which are the genuine dimensions of the element no matter how stretched it is by its inner content.

I'm guessing that there are some things that one can do and the other one cannot as I was using
to return the dimensions of a window and document, where FF had no issues doing this but IE threw back an error at me. So I'm guessing that they might work in some browsers and but others. So would I have to use both together for 100% cross browser compatibility or just for certain cases?

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.