35 of 119 menu

The outerHeight method

The outerHeight method allows you to get and change the height of an element taking into account the internal padding, border and, selectively, the external padding of the element. It is important to remember that we will get 'calculated value' height. Errors in calculation can also occur if the user changes the page dimensions, or if the element or its parent is hidden.

Syntax

This is how we can get the height of an element. This method can take an optional parameter in the form of true or false (false is the default), depending on whether the outer padding will be taken into account or not. In some cases, the resulting values ​​can be fractional:

$(selector).outerWidth([including_margin]);

To change the width of an element, you can simply pass a number (for example, 400), then the units of measurement will be pixels, or a string indicating the units of measurement (for example, '10em'):

$(selector).outerHeight(new value, [including_margin]);

We can also apply the given function to each element in the set. In this case, the function will receive the number of the element in the set as the first parameter, and the current value of the given height for a specific element as the second parameter. this inside the function will point to the current element. The value of the element's width will change to the one returned by the function:

$(selector).outerHeight(function(number in set, current height value));

Example

For comparison, let's display information about the paragraph height #test, obtained by the methods height, innerHeight and outerHeight:

<p id="test">text</p> <p id="out1"></p> <p id="out2"></p> <p id="out3"></p> <p id="out4"></p> p { margin: 10px; padding: 5px; border: 2px solid blue; } let h1 = $('#test').height(); let h2 = $('#test').innerHeight(); let h3 = $('#test').outerHeight(); let h4 = $('#test').outerHeight(true); $('#out1').text(h1); $('#out2').text(h2); $('#out3').text(h3); $('#out4').text(h4);

See also

  • method height,
    which allows you to get and change the height of an element
  • method innerHeight,
    which allows you to get and change the height of an element, taking into account its internal paddings
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline