Easy Tutorial
❮ Css Scrollleft Misc Callbacks Add ❯

jQuery width() Method

jQuery HTML/CSS Methods

Example

Return the width of a <div> element:

$("button").click(function(){
    alert($("div").width());
});

Definition and Usage

The width() method sets or returns the width of the selected elements.

When this method is used to return the width,

When this method is used to set the width, it sets the width of all matched elements.

As shown in the image below, this method does not include padding, border, or margin.


Related Methods:


Syntax

Return width:

Set width:

Set width using a function:

Parameter Description
value Required when setting the width. Specifies the width of the element in units such as px, em, pt, etc. <br>The default unit is px.
function (index,currentwidth) Optional. Specifies a function that returns the new width of the selected element. index - Returns the index position of the element in the set.<br>currentwidth - Returns the current width of the selected element.

More Examples

Set the width of an element

Increase width using a function

Return the width of the document and window elements

Display dimensions using related methods


jQuery HTML/CSS Methods

❮ Css Scrollleft Misc Callbacks Add ❯