Javatpoint Logo
Javatpoint Logo

jQuery width()

jQuery width() method is used to return or set the width of matched element.

To return width: When this method is used to return the width, it returns the width of first matched element.

To set width:When this method is used to set the width, it sets the width for every matched element.

This method is one of a jQuery dimension.

List of jQuery dimension:

  • width()
  • height()
  • innerWidth()
  • innerHeight()
  • outerWidth()
  • outerHeight()

Syntax:

To return the width:

To set the width:

To set the width using a function:

Parameters of jQuery width() method

Parameter Description
Value It is a mandatory parameter. It is used for setting width. It specifies the width in px, em, pt etc. The default value of jQuery width() method is px.
Function(index, currentwidth) It is an optional parameter. It specifies a function that provides the new width of selected element.
  • Index:IIt provides the index position of the element in the set.
  • currentwidth:It provides the current width of the selected element.

Example of jQuery width() method

Let's take an example to demonstrate the effect of jQuery width() method.

To return width:

Test it Now

jQuery width() example 2

To set width:

Test it Now
Next TopicjQuery height()





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA