JQuery Programmer Question:
Explain width() vs css('width')?

Answer:
1. In jQuery, there are two way to change the width of an element.
2. One way is using .css('width') and other way is using .width().
For example
$('#mydiv').css('width','300px');
$('#mydiv').width(100);
1. The difference in .css('width') and .width() is the data type of value we specify or return from the both functions.
2. In .css('width') we have to add "px" in the width value while in .width() we don't have to add.
3. When you want to get the width of "mydiv" element then .css('width') will return '300px' while .width() will return only integer value 300.
2. One way is using .css('width') and other way is using .width().
For example
$('#mydiv').css('width','300px');
$('#mydiv').width(100);
1. The difference in .css('width') and .width() is the data type of value we specify or return from the both functions.
2. In .css('width') we have to add "px" in the width value while in .width() we don't have to add.
3. When you want to get the width of "mydiv" element then .css('width') will return '300px' while .width() will return only integer value 300.
Previous Question | Next Question |
How to binds a function to be executed whenever the DOM is ready to be traversed and manipulated using jQuery? | Explain slideToggle() effect? |