English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

jQuery innerWidth() method

jQuery HTML/Méthodes CSS

The innerWidth() method gets or sets the internal width of the selected element (including padding, but not including margin and border).

When using the innerWidth() methodGetWhen setting theThe first selected elementwidth.

When using the innerWidth() methodSetWhen setting theAll selected elementswidth.

As shown in the figure below, the innerWidth() method includes padding, but does not include margin and border:

The width value can also be relative. If a leading+=-If the value is a character sequence, calculate the target width by adding or subtracting the given number from the current value (for example, innerWidth("-= 100”))。

Syntax:

Get the internal width:

$(selector).innerWidth()

Set the internal width:

$(selector).innerWidth(value)

Example

Get the internal width of the DIV element:

$("div").click(function(){
  $(this).innerWidth();
});
Vérifiez et voyez‹/›

Set the internal width of all paragraphs:

$("button").click(function(){
  $("p").innerWidth("}}100);
});
Vérifiez et voyez‹/›

Configure the internal width of all paragraphs using different unit settings:

$("#btn1").click(function(){
  $("p").innerWidth("}}100);
});
$("#btn2").click(function(){
  $("p").innerWidth("10em");
});
$("#btn3").click(function(){
  $("p").innerWidth("100vw");
});
Vérifiez et voyez‹/›

Affichez la différence entre width(), height(), innerHeight(), innerWidth(), outerWidth() et outerHeight() :

$("button").click(function(){
  $("div").width();
  $("div").innerWidth();
  $("div").outerWidth();
  $("div").height();
  $("div").innerHeight();
  $("div").outerHeight();
});
Vérifiez et voyez‹/›

Valeur du paramètre

ParamètreDescription
valueEntier représentant le nombre de pixels, ou entier avec unité de mesure optionnelle ajoutée (comme chaîne)

jQuery HTML/Méthodes CSS