Description
The .width() method sets or returns the width of the selected element.
Return Width
Returns the width of the FIRST matched element.
v1.0
This method has the form:
.width()
Return Value
This form returns an Integer object.
Set Width
Sets the width of ALL matched elements
v1.0
This method has the alternate form:
.width(value)
Parameter | Description |
---|---|
value | (required) Specifies the width in px, em, %, etc. Default unit is px |
Return Value
This form returns a jQuery object.
Set Width Using a Function
Using a function to set the width of ALL matched elements
v1.4.1
This method has the alternate form:
.width(function(index,oldwidth))
Parameter | Description |
---|---|
function(index, oldwidth) | Specifies a function that returns the new width of selected elements.
|
Return Value
This form returns a jQuery object.
Examples
Set the width of all p elements:
$("button").click(function(){
$("p").width(200);
});