.width()
methodThe .width()
method in jQuery is used to get/set the width of the matched element.
.width()
method Syntax.width() .width(value) .width(function)
Parameter | Type | Description |
---|---|---|
value |
String,Number | the width value to set |
funtion(index, oldwidth) |
Function | a function returning the width to set. index is the position of the element in the set.(based on 0) oldwidth is the old width. |
.width()
Get the width of the first matched element.(If the element is not visible, the width would be 0 )
Get the width of the first paragraph
$("p").width();
.width(function)
Set the element 20px higher than the previous.
$("p").width(function(index,oldValue){ return 20*index + oldValue; });