To generalize Solution 1 a bit:
That solution shows that you don't have to change CSS in this case, because
width
is important enough to be directly implemented in jQuery. Such rendered properties as
width
are implemented in two forms: 1) as the attribute of the element; 2) as the part of the CSS style of one element or the set of elements sharing some CSS class.
If you do it all manually and statically, CSS is always preferred, but if you implement some properties and make the dynamic in CSS, both ways can be used, depending in the situation.
To modify CSS on some events, please use:
http://api.jquery.com/category/css[
^].
For
width
only, it could be a bit of overkill, but often you need to modify the whole set of attributes at once. In such cases, there is nothing better than replacing, toggling or adding/removing a CSS class.
—SA