Metoda jQuery outerWidth()

❮ Metody jQuery HTML/CSS

Przykład

Zwróć zewnętrzną szerokość elementu <div>:

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

Definicja i użycie

Metoda outerWidth() zwraca zewnętrzną szerokość PIERWSZEGO dopasowanego elementu.

Jak pokazano na poniższym obrazku, ta metoda obejmuje dopełnienie i obramowanie.

Wskazówka: aby uwzględnić margines, użyj opcji externalWidth(true).

jQuery Wymiary


Powiązane metody:

  • width() - Ustawia lub zwraca szerokość elementu
  • height() - Ustawia lub zwraca wysokość elementu
  • innerWidth() — Zwraca szerokość elementu (wraz z dopełnieniem)
  • innerHeight() — Zwraca wysokość elementu (w tym dopełnienie)
  • outerHeight() — Zwraca wysokość elementu (w tym dopełnienie i obramowanie).

Składnia

$(selector).outerWidth(includeMargin)

Parameter Description
includeMargin Optional. A Boolean value specifying whether or not to include the margin
  • false - Default. Does not include the margin
  • true - Includes the margin

Spróbuj sam - przykłady


Określ, czy uwzględnić margines.


Jak używać width(), height(), innerHeight(), innerWidth(), outerWidth() i outerHeight().


❮ Metody jQuery HTML/CSS