Reputation: 25
$(selector).height(value)
$(selector).width(value)
We can use the above two ways to change the height
or width
of a div
or element. but there is also another way, like
$(selector).css({"height": "100px", "width":"100px"})
since the second way can be applied to all css element, why the first method?
Upvotes: 0
Views: 82
Reputation: 504
There is one major difference: in width()
and height()
you can use function as parameter which returns a value
.height( function(index, height) )
Upvotes: 0
Reputation: 179402
In jQuery, there's often more than one way to do it.
.height
and .width
are useful convenience methods which simplify programming, while .css
is the general method that encompasses all of that functionality (at the expense of being somewhat more cumbersome).
Upvotes: 2