jQuery height()メソッド

❮jQueryHTML/ CSSメソッド

<div>要素の高さを返します。

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

定義と使用法

height()メソッドは、選択した要素の高さを設定または返します。

このメソッドを使用して高さを返す場合、最初に一致した要素の高さを返します。

このメソッドを使用して高さを設定すると、一致するすべての要素の高さが設定されます。

下の画像が示すように、この方法にはパディング、ボーダー、マージンは含まれていません。

jQueryディメンション


関連する方法:



構文

高さを返します:

$(selector).height()

高さを設定します。

$(selector).height(value)

次の関数を使用して高さを設定します。

$(selector).height(function(index,currentheight))

Parameter Description
value Required for setting height. Specifies the height in px, em, pt, etc.
Default unit is px
function(index,currentheight) Optional. Specifies a function that returns the new height of selected elements
  • index - Returns the index position of the element in the set
  • currentheight - Returns the current height of the selected element

自分で試してみてください-例


の高さを設定するさまざまな単位を使用して要素の高さを設定する方法。


を使用して高さを増やす関数を使用して要素の高さを増やす方法。


の現在の高さを返す方法。


するwidth()、height()、innerHeight()、innerWidth()、outerWidth()、outerHeight()の使用方法。


❮jQueryHTML/ CSSメソッド