jQuery Tutorial Tutorials - jQuery .innerWidth() method

jQuery .innerWidth() method

The .innerWidth() method in jQuery is used to get/set the inner width (including padding but not border) of the matched element.

jQuery .innerWidth() method Syntax

.innerWidth()
.innerWidth(value)
.innerWidth(function)
Parameter Type Description
value String,Number the width value to set
funtion(index, oldWidth) Function a function returning the inner width to set.
index is the position of the element in the set.(based on 0)
oldWidth is the old inner width.

.innerWidth()

Get the current computed inner width(including padding but not border) of the first matched element.(If the element is not visible, the width would be 0 )

example

Get the inner width of the first paragraph

$("p").innerWidth();

Try now

.innerWidth(value)

Set the inner width(including padding but not border) of every matched elements.

example

Set the innerWidth of each p to 300px

$("p").innerWidth(300);

Try now

.innerWidth(function)

example

Set the innerWidth of the element to 20px wider than the previous.

$("p").innerWidth(function(index,oldValue){
    return 20*index + oldValue;
});

Try now

Date:2019-08-20 15:32:27 From:www.Lautturi.com author:Lautturi