Jquery get value magin-top css by id năm 2024

To get the height of an element, there are five common methods in JavaScript. Lets see the differences between each and when they should be used. Only the last method gives the correct rendered height instead of the layout height.

  • style.height
  • jQuery[ height, innerHeight, outerHeight ]
  • clientHeight, offsetHeight, scrollHeight
  • getComputedStyle
  • getBoundingClientRect[].height

Rendered height is the height that the element gets finally after all the styles and transformations are applied on that element. For example, An element has height of 100px and then gets a transform:scale[0.5]. Its rendered height is 50px [after the transformation] and layout height is 100px.

style.height We can use style.height on any selected element and it will return its height. Does not include the padding, border or margin. Italways return the height along with the specific unit.

Note: Only works if we explicitly set the height as inline using the style attribute in HTML.

Syntax:

let height = document.getElementById["someId"].style.height;

Example:

HTML

let height = $["

div1"].height[];

1

let height = $["

div1"].height[];

2

let height = $["

div1"].height[];

3

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

2

let height = $["

div1"].height[];

6

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = $["

div1"].innerHeight[];

0

let height = $["

div1"].innerHeight[];

1

let height = $["

div1"].innerHeight[];

2

let height = $["

div1"].innerHeight[];

3

let height = $["

div1"].innerHeight[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = $["

div1"].innerHeight[];

7

let height = $["

div1"].height[];

4

let height = $["

div1"].innerHeight[];

9

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

0

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

2

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

4

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

6

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

8

let height = $["

div1"].innerHeight[];

9

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

0

let height = $["

div1"].innerHeight[];

9

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

2

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

4

let height = $["

div1"].innerHeight[];

9

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

0

let height = $["

div1"].height[];

8

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].innerHeight[];

7

let height = $["

div1"].height[];

4

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].height[];

6

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

2

let height = document.getElementById["div1"].clientHeight;

5

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = document.getElementById["div1"].clientHeight;

9

let height = document.getElementById["div1"].offsetHeight;

0

let height = $["

div1"].innerHeight[];

2

let height = document.getElementById["div1"].offsetHeight;

2

let height = $["

div1"].height[];

4

let height = $["

div1"].innerHeight[];

9

let height = $["

div1"].height[];

2

let height = document.getElementById["div1"].offsetHeight;

6

let height = $["

div1"].height[];

4

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = document.getElementById["div1"].offsetHeight;

9

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = document.getElementById["div1"].scrollHeight

1

let height = $["

div1"].innerHeight[];

9

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = document.getElementById["div1"].offsetHeight;

6

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = document.getElementById["div1"].clientHeight;

9

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = document.getElementById["div1"].clientHeight;

9

let height = document.getElementById["div1"].offsetHeight;

0

let height = $["

div1"].innerHeight[];

2

let height = getComputedStyle[document.getElementById["div1"]].height;

5

let height = $["

div1"].innerHeight[];

7

let height = $["

div1"].innerHeight[];

2

let height = getComputedStyle[document.getElementById["div1"]].height;

8

let height = $["

div1"].height[];

4

let height = $["

div1"].innerHeight[];

9

let height = $["

div1"].height[];

2

let height = document.getElementById["div1"].offsetHeight;

6

let height = getComputedStyle[document.getElementById["div1"]] .getPropertyValue["height"]; let marginTop = getComputedStyle[document.getElementById["div1"]] .getPropertyValue["margin-top"]; let borderBottom = getComputedStyle[document.getElementById["div1"]] .getPropertyValue["border-bottom"];

3

let height = document.getElementById["div1"].offsetHeight;

6

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = document.getElementById["div1"].clientHeight;

9

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = $["

div1"].height[];

02

let height = $["

div1"].height[];

03

let height = $["

div1"].innerHeight[];

2

let height = $["

div1"].height[];

05

let height = $["

div1"].height[];

4

let height = $["

div1"].innerHeight[];

9

let height = $["

div1"].height[];

08

let height = $["

div1"].height[];

8

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].height[];

02

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = $["

div1"].height[];

15

let height = $["

div1"].height[];

4

let height = $["

div1"].innerHeight[];

9

let height = $["

div1"].height[];

18

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].height[];

20

let height = $["

div1"].height[];

21

let height = $["

div1"].height[];

22

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].height[];

20

let height = $["

div1"].height[];

21

let height = $["

div1"].height[];

26

let height = $["

div1"].innerHeight[];

9

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

0

let height = $["

div1"].height[];

8

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].height[];

15

let height = $["

div1"].height[];

4

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = document.getElementById["div1"].clientHeight;

5

let height = $["

div1"].height[];

4

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].height[];

3

let height = $["

div1"].height[];

4

Output: It returns empty string for “div1” and it returns “100px” for “div2”

Conclusion: It returns whatever height is specified in inline style attribute only. It does not factor in any transformations, like scale. It is not reliable and should not be used as inline styles are not ideal.

jQuery[height, innerHeight, outerHeight] height[] It returns the current height of the element. It does not include the padding, border or margin. It always returns a unit-less pixel value.

Note: The height[] will always return the content height, regardless of the value of CSS box-sizing property.

Syntax:

let height = $["

div1"].height[];

Example 2:

HTML

let height = $["

div1"].height[];

1

let height = $["

div1"].height[];

2

let height = $["

div1"].height[];

3

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

2

let height = $["

div1"].height[];

6

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = $["

div1"].innerHeight[];

0

let height = $["

div1"].innerHeight[];

1

let height = $["

div1"].innerHeight[];

2

let height = $["

div1"].innerHeight[];

3

let height = $["

div1"].innerHeight[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = $["

div1"].innerHeight[];

7

let height = $["

div1"].height[];

4

let height = $["

div1"].innerHeight[];

9

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

0

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

2

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

4

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

6

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

8

let height = $["

div1"].innerHeight[];

9

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

0

let height = $["

div1"].innerHeight[];

9

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

2

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

4

let height = $["

div1"].innerHeight[];

9

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

0

let height = $["

div1"].height[];

8

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].innerHeight[];

7

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = $["

div1"].height[];

15

let height = $["

div1"].height[];

82

let height = $["

div1"].height[];

83

let height = $["

div1"].height[];

8

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].height[];

15

let height = $["

div1"].height[];

4

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].height[];

6

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

2

let height = document.getElementById["div1"].clientHeight;

5

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = document.getElementById["div1"].clientHeight;

9

let height = document.getElementById["div1"].offsetHeight;

0

let height = $["

div1"].innerHeight[];

2

let height = document.getElementById["div1"].offsetHeight;

2

let height = $["

div1"].height[];

4

let height = $["

div1"].innerHeight[];

9

let height = $["

div1"].height[];

2

let height = document.getElementById["div1"].offsetHeight;

6

let height = $["

div1"].innerHeight[];

04

let height = document.getElementById["div1"].offsetHeight;

6

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = document.getElementById["div1"].clientHeight;

9

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = $["

div1"].height[];

02

let height = $["

div1"].height[];

03

let height = $["

div1"].innerHeight[];

2

let height = $["

div1"].height[];

05

let height = $["

div1"].height[];

4

let height = $["

div1"].innerHeight[];

9

let height = $["

div1"].height[];

08

let height = $["

div1"].height[];

8

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].height[];

02

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = $["

div1"].height[];

15

let height = $["

div1"].height[];

4

let height = $["

div1"].innerHeight[];

9

let height = $["

div1"].height[];

18

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].innerHeight[];

31

let height = $["

div1"].innerHeight[];

9

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

0

let height = $["

div1"].height[];

8

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].height[];

15

let height = $["

div1"].height[];

4

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = document.getElementById["div1"].clientHeight;

5

let height = $["

div1"].height[];

4

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].height[];

3

let height = $["

div1"].height[];

4

Output: It returns unit-less pixel value as 100.

Output:

innerHeight[] It returns the current height of the element including the top and bottom padding but not border. It always returns a unit-less pixel value.

Syntax:

let height = $["

div1"].innerHeight[];

Example 3:

HTML

let height = $["

div1"].height[];

1

let height = $["

div1"].height[];

2

let height = $["

div1"].height[];

3

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

2

let height = $["

div1"].height[];

6

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = $["

div1"].innerHeight[];

0

let height = $["

div1"].innerHeight[];

1

let height = $["

div1"].innerHeight[];

2

let height = $["

div1"].innerHeight[];

3

let height = $["

div1"].innerHeight[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = $["

div1"].innerHeight[];

7

let height = $["

div1"].height[];

4

let height = $["

div1"].innerHeight[];

9

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

0

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

2

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

4

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

6

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

8

let height = $["

div1"].innerHeight[];

9

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

0

let height = $["

div1"].innerHeight[];

9

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

2

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

4

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].innerHeight[];

79

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].innerHeight[];

81

let height = $["

div1"].innerHeight[];

9

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

0

let height = $["

div1"].height[];

8

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].innerHeight[];

7

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = $["

div1"].height[];

15

let height = $["

div1"].height[];

82

let height = $["

div1"].height[];

83

let height = $["

div1"].height[];

8

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].height[];

15

let height = $["

div1"].height[];

4

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].height[];

6

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

2

let height = document.getElementById["div1"].clientHeight;

5

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = document.getElementById["div1"].clientHeight;

9

let height = document.getElementById["div1"].offsetHeight;

0

let height = $["

div1"].innerHeight[];

2

let height = document.getElementById["div1"].offsetHeight;

2

let height = $["

div1"].height[];

4

let height = $["

div1"].innerHeight[];

9

let height = $["

div1"].height[];

2

let height = document.getElementById["div1"].offsetHeight;

6

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

13

let height = document.getElementById["div1"].offsetHeight;

6

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = document.getElementById["div1"].clientHeight;

9

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = $["

div1"].height[];

02

let height = $["

div1"].height[];

03

let height = $["

div1"].innerHeight[];

2

let height = $["

div1"].height[];

05

let height = $["

div1"].height[];

4

let height = $["

div1"].innerHeight[];

9

let height = $["

div1"].height[];

08

let height = $["

div1"].height[];

8

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].height[];

02

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = $["

div1"].height[];

15

let height = $["

div1"].height[];

4

let height = $["

div1"].innerHeight[];

9

let height = $["

div1"].height[];

18

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

40

let height = $["

div1"].innerHeight[];

9

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

0

let height = $["

div1"].height[];

8

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].height[];

15

let height = $["

div1"].height[];

4

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = document.getElementById["div1"].clientHeight;

5

let height = $["

div1"].height[];

4

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].height[];

3

let height = $["

div1"].height[];

4

Output: It returns 120 which is [10[top padding] + 100[content height] + 10[bottom-padding]]

outerHeight[] It returns the current height of the element including the padding, border and margin optionally. It always returns a unit-less pixel value.

Syntax:

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

Example 4:

HTML

let height = $["

div1"].height[];

1

let height = $["

div1"].height[];

2

let height = $["

div1"].height[];

3

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

2

let height = $["

div1"].height[];

6

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = $["

div1"].innerHeight[];

0

let height = $["

div1"].innerHeight[];

1

let height = $["

div1"].innerHeight[];

2

let height = $["

div1"].innerHeight[];

3

let height = $["

div1"].innerHeight[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = $["

div1"].innerHeight[];

7

let height = $["

div1"].height[];

4

let height = $["

div1"].innerHeight[];

9

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

0

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

2

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

4

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

6

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

8

let height = $["

div1"].innerHeight[];

9

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

0

let height = $["

div1"].innerHeight[];

9

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

2

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

4

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].innerHeight[];

79

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].innerHeight[];

81

let height = $["

div1"].innerHeight[];

9

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

0

let height = $["

div1"].height[];

8

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].innerHeight[];

7

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = $["

div1"].height[];

15

let height = $["

div1"].height[];

82

let height = $["

div1"].height[];

83

let height = $["

div1"].height[];

8

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].height[];

15

let height = $["

div1"].height[];

4

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].height[];

6

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

2

let height = document.getElementById["div1"].clientHeight;

5

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = document.getElementById["div1"].clientHeight;

9

let height = document.getElementById["div1"].offsetHeight;

0

let height = $["

div1"].innerHeight[];

2

let height = document.getElementById["div1"].offsetHeight;

2

let height = $["

div1"].height[];

4

let height = $["

div1"].innerHeight[];

9

let height = $["

div1"].height[];

2

let height = document.getElementById["div1"].offsetHeight;

6

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

22

let height = document.getElementById["div1"].offsetHeight;

6

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = document.getElementById["div1"].clientHeight;

9

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = $["

div1"].height[];

02

let height = $["

div1"].height[];

03

let height = $["

div1"].innerHeight[];

2

let height = $["

div1"].height[];

05

let height = $["

div1"].height[];

4

let height = $["

div1"].innerHeight[];

9

let height = $["

div1"].height[];

08

let height = $["

div1"].height[];

8

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].height[];

02

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = $["

div1"].height[];

15

let height = $["

div1"].height[];

4

let height = $["

div1"].innerHeight[];

9

let height = $["

div1"].height[];

18

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

49

let height = $["

div1"].innerHeight[];

9

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

0

let height = $["

div1"].height[];

8

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].height[];

15

let height = $["

div1"].height[];

4

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = document.getElementById["div1"].clientHeight;

5

let height = $["

div1"].height[];

4

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].height[];

3

let height = $["

div1"].height[];

4

Output:

[1[top border]+ 10[top padding]+ 100[content height]+1 0[bottom-padding]+ 1[bottom border]

Note: The value reported by height[], innerHeight[] and outerHeight[] is not guaranteed to be accurate when the element or its parent is hidden. To get accurate results, ensure the element is visible before using these methods. jQuery will attempt to temporarily show and then re-hide an element in order to measure its dimensions, but this is unreliable and [even when accurate] can significantly impact page performance. This show-and-rehide measurement feature may be removed in a future version of jQuery.

Conclusion:

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

All these return only the layout height, not the rendered height.

clientHeight, offsetHeight, scrollHeight clientHeight[] It returns the height of the displayed content from the element [including vertical padding but not border or margin or scrollbar]. It always returns an integer value in pixels. If element is hidden, then 0 is returned. If its a scrollable element, then it will only give the height of the visible part.

Syntax:

let height = document.getElementById["div1"].clientHeight;

Example 5:

HTML

let height = $["

div1"].height[];

1

let height = $["

div1"].height[];

2

let height = $["

div1"].height[];

3

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

2

let height = $["

div1"].height[];

6

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = $["

div1"].innerHeight[];

0

let height = $["

div1"].innerHeight[];

1

let height = $["

div1"].innerHeight[];

2

let height = $["

div1"].innerHeight[];

3

let height = $["

div1"].innerHeight[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = $["

div1"].innerHeight[];

7

let height = $["

div1"].height[];

4

let height = $["

div1"].innerHeight[];

9

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

0

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

2

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

4

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

6

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

8

let height = $["

div1"].innerHeight[];

9

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

0

let height = $["

div1"].innerHeight[];

9

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

2

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

4

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].innerHeight[];

79

let height = $["

div1"].innerHeight[];

9

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

0

let height = $["

div1"].height[];

8

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].innerHeight[];

7

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = $["

div1"].height[];

15

let height = $["

div1"].height[];

82

let height = $["

div1"].height[];

83

let height = $["

div1"].height[];

8

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].height[];

15

let height = $["

div1"].height[];

4

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].height[];

6

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

2

let height = document.getElementById["div1"].clientHeight;

5

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = document.getElementById["div1"].clientHeight;

9

let height = document.getElementById["div1"].offsetHeight;

0

let height = $["

div1"].innerHeight[];

2

let height = document.getElementById["div1"].offsetHeight;

2

let height = $["

div1"].height[];

4

let height = $["

div1"].innerHeight[];

9

let height = $["

div1"].height[];

2

let height = document.getElementById["div1"].offsetHeight;

6

let height = document.getElementById["div1"].clientHeight;

29

let height = document.getElementById["div1"].offsetHeight;

6

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = document.getElementById["div1"].clientHeight;

9

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = $["

div1"].height[];

02

let height = $["

div1"].height[];

03

let height = $["

div1"].innerHeight[];

2

let height = $["

div1"].height[];

05

let height = $["

div1"].height[];

4

let height = $["

div1"].innerHeight[];

9

let height = $["

div1"].height[];

08

let height = $["

div1"].height[];

8

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].height[];

02

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = $["

div1"].height[];

15

let height = $["

div1"].height[];

4

let height = $["

div1"].innerHeight[];

9

let height = $["

div1"].height[];

18

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].height[];

20

let height = $["

div1"].height[];

21

let height = document.getElementById["div1"].clientHeight;

58

let height = $["

div1"].innerHeight[];

9

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

0

let height = $["

div1"].height[];

8

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].height[];

15

let height = $["

div1"].height[];

4

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = document.getElementById["div1"].clientHeight;

5

let height = $["

div1"].height[];

4

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].height[];

3

let height = $["

div1"].height[];

4

Output:

It returns 120 which is [10[top padding] + 100[content height] + 10[bottom-padding]]

Conclusion: If we want to find the height of the actual displayed content use clientHeight. It returns the layout height of the currently visible part of the element which is rounded to an integer value even if the result is a fraction.

offsetHeight[] It returns the height that the element occupies including the vertical padding, border and scrollbars [if any]. It does not include the margin. It always returns an integer value in pixels. If element is hidden, then 0 is returned.

Note: It does not include the height of pseudo elements such as ::after or ::before

Syntax:

let height = document.getElementById["div1"].offsetHeight;

Example 6:

HTML

let height = $["

div1"].height[];

1

let height = $["

div1"].height[];

2

let height = $["

div1"].height[];

3

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

2

let height = $["

div1"].height[];

6

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = $["

div1"].innerHeight[];

0

let height = $["

div1"].innerHeight[];

1

let height = $["

div1"].innerHeight[];

2

let height = $["

div1"].innerHeight[];

3

let height = $["

div1"].innerHeight[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = $["

div1"].innerHeight[];

7

let height = $["

div1"].height[];

4

let height = $["

div1"].innerHeight[];

9

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

0

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

2

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

4

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

6

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

8

let height = $["

div1"].innerHeight[];

9

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

0

let height = $["

div1"].innerHeight[];

9

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

2

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

4

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].innerHeight[];

79

let height = $["

div1"].innerHeight[];

9

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

0

let height = $["

div1"].height[];

8

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].innerHeight[];

7

let height = $["

div1"].height[];

4

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].height[];

6

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

2

let height = document.getElementById["div1"].clientHeight;

5

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = document.getElementById["div1"].clientHeight;

9

let height = document.getElementById["div1"].offsetHeight;

0

let height = $["

div1"].innerHeight[];

2

let height = document.getElementById["div1"].offsetHeight;

2

let height = $["

div1"].height[];

4

let height = $["

div1"].innerHeight[];

9

let height = $["

div1"].height[];

2

let height = document.getElementById["div1"].offsetHeight;

6

let height = document.getElementById["div1"].offsetHeight;

29

let height = document.getElementById["div1"].offsetHeight;

6

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = document.getElementById["div1"].clientHeight;

9

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = $["

div1"].height[];

02

let height = $["

div1"].height[];

03

let height = $["

div1"].innerHeight[];

2

let height = $["

div1"].height[];

05

let height = $["

div1"].height[];

4

let height = $["

div1"].innerHeight[];

9

let height = $["

div1"].height[];

08

let height = $["

div1"].height[];

8

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].height[];

02

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = $["

div1"].height[];

15

let height = $["

div1"].height[];

4

let height = $["

div1"].innerHeight[];

9

let height = $["

div1"].height[];

18

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].height[];

20

let height = $["

div1"].height[];

21

let height = document.getElementById["div1"].offsetHeight;

58

let height = $["

div1"].innerHeight[];

9

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

0

let height = $["

div1"].height[];

8

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].height[];

15

let height = $["

div1"].height[];

4

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = document.getElementById["div1"].clientHeight;

5

let height = $["

div1"].height[];

4

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].height[];

3

let height = $["

div1"].height[];

4

Output:

It returns 122 which is [1[border-top] + 10[padding-top ]+ 100[contentHeight] + 10[padding-bottom] + 1[border-bottom]]

Conclusion: If you need to know the total height of an element occupies including the width of the visible content, scrollbars [if any], padding, and border, we can use offsetWidth. It returns the layout height of the currently visible part of the element which is rounded to an integer value.

scrollHeight[] It returns the height of the entire content of an element, even if only part of it is visible due to scrollbars. It always returns an integer value in pixels. If the element is hidden, then 0 is returned.

Its similar to clientHeight as it includes the element and its padding, but not its border, margin or horizontal scrollbar [if present]. It can also include the height of pseudo-elements such as ::before or ::after. If the element’s content can fit without a need for vertical scrollbar, its scrollHeight is equal to clientHeight.

Syntax:

let height = document.getElementById["div1"].scrollHeight

Example 7:

HTML

let height = $["

div1"].height[];

1

let height = $["

div1"].height[];

2

let height = $["

div1"].height[];

3

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

2

let height = $["

div1"].height[];

6

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = $["

div1"].innerHeight[];

0

let height = $["

div1"].innerHeight[];

1

let height = $["

div1"].innerHeight[];

2

let height = $["

div1"].innerHeight[];

3

let height = $["

div1"].innerHeight[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = $["

div1"].innerHeight[];

7

let height = $["

div1"].height[];

4

let height = $["

div1"].innerHeight[];

9

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

0

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

2

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

4

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

6

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

8

let height = $["

div1"].innerHeight[];

9

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

0

let height = $["

div1"].innerHeight[];

9

let height = document.getElementById["div1"].scrollHeight

02

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = document.getElementById["div1"].scrollHeight

04

let height = $["

div1"].innerHeight[];

9

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

0

let height = $["

div1"].innerHeight[];

9

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

2

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

4

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].innerHeight[];

79

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = document.getElementById["div1"].scrollHeight

14

let height = $["

div1"].innerHeight[];

9

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

0

let height = $["

div1"].height[];

8

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].innerHeight[];

7

let height = $["

div1"].height[];

4

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].height[];

6

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

2

let height = document.getElementById["div1"].clientHeight;

5

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = document.getElementById["div1"].clientHeight;

9

let height = document.getElementById["div1"].offsetHeight;

0

let height = $["

div1"].innerHeight[];

2

let height = document.getElementById["div1"].offsetHeight;

2

let height = $["

div1"].height[];

4

let height = $["

div1"].innerHeight[];

9

let height = $["

div1"].height[];

2

let height = document.getElementById["div1"].offsetHeight;

6

let height = document.getElementById["div1"].offsetHeight;

29

let height = document.getElementById["div1"].offsetHeight;

6

let height = $["

div1"].height[];

4

let height = $["

div1"].innerHeight[];

9

let height = document.getElementById["div1"].scrollHeight

41

let height = $["

div1"].innerHeight[];

9

let height = document.getElementById["div1"].scrollHeight

43

let height = $["

div1"].innerHeight[];

9

let height = document.getElementById["div1"].scrollHeight

45

let height = $["

div1"].innerHeight[];

9

let height = document.getElementById["div1"].scrollHeight

47

let height = $["

div1"].innerHeight[];

9

let height = document.getElementById["div1"].scrollHeight

49

let height = $["

div1"].innerHeight[];

9

let height = document.getElementById["div1"].scrollHeight

51

let height = $["

div1"].innerHeight[];

9

let height = document.getElementById["div1"].scrollHeight

53

let height = $["

div1"].innerHeight[];

9

let height = document.getElementById["div1"].scrollHeight

55

let height = $["

div1"].innerHeight[];

9

let height = document.getElementById["div1"].scrollHeight

57

let height = $["

div1"].innerHeight[];

9

let height = document.getElementById["div1"].scrollHeight

59

let height = $["

div1"].innerHeight[];

9

let height = document.getElementById["div1"].scrollHeight

61

let height = $["

div1"].innerHeight[];

9

let height = document.getElementById["div1"].scrollHeight

63

let height = $["

div1"].innerHeight[];

9

let height = document.getElementById["div1"].scrollHeight

65

let height = $["

div1"].innerHeight[];

9

let height = document.getElementById["div1"].scrollHeight

67

let height = $["

div1"].innerHeight[];

9

let height = document.getElementById["div1"].scrollHeight

69

let height = $["

div1"].innerHeight[];

9

let height = document.getElementById["div1"].scrollHeight

71

let height = $["

div1"].innerHeight[];

9

let height = document.getElementById["div1"].scrollHeight

73

let height = $["

div1"].innerHeight[];

9

let height = document.getElementById["div1"].scrollHeight

75

let height = $["

div1"].innerHeight[];

9

let height = document.getElementById["div1"].scrollHeight

77

let height = $["

div1"].innerHeight[];

9

let height = document.getElementById["div1"].scrollHeight

79

let height = $["

div1"].innerHeight[];

9

let height = document.getElementById["div1"].scrollHeight

81

let height = $["

div1"].innerHeight[];

9

let height = document.getElementById["div1"].scrollHeight

83

let height = $["

div1"].innerHeight[];

9

let height = document.getElementById["div1"].scrollHeight

85

let height = $["

div1"].innerHeight[];

9

let height = document.getElementById["div1"].scrollHeight

87

let height = $["

div1"].innerHeight[];

9

let height = document.getElementById["div1"].scrollHeight

89

let height = $["

div1"].innerHeight[];

9

let height = document.getElementById["div1"].scrollHeight

91

let height = $["

div1"].innerHeight[];

9

let height = document.getElementById["div1"].scrollHeight

93

let height = $["

div1"].innerHeight[];

9

let height = document.getElementById["div1"].scrollHeight

95

let height = $["

div1"].innerHeight[];

9

let height = document.getElementById["div1"].scrollHeight

97

let height = $["

div1"].innerHeight[];

9

let height = document.getElementById["div1"].scrollHeight

99

let height = $["

div1"].innerHeight[];

9

let height = getComputedStyle[document.getElementById["div1"]].height;

01

let height = $["

div1"].innerHeight[];

9

let height = getComputedStyle[document.getElementById["div1"]].height;

03

let height = $["

div1"].height[];

8

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = document.getElementById["div1"].clientHeight;

9

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = $["

div1"].height[];

02

let height = $["

div1"].height[];

03

let height = $["

div1"].innerHeight[];

2

let height = $["

div1"].height[];

05

let height = $["

div1"].height[];

4

let height = $["

div1"].innerHeight[];

9

let height = getComputedStyle[document.getElementById["div1"]].height;

16

let height = $["

div1"].height[];

02

let height = $["

div1"].height[];

4

let height = $["

div1"].height[];

8

let height = $["

div1"].height[];

2

let height = $["

div1"].height[];

15

let height = $["

div1"].height[];

4

let height = $["

div1"].innerHeight[];

9

let height = $["

div1"].height[];

18

let height = $["

div1"].outerHeight[];

let height = $["

div1"].outerHeight[];

1

let height = $["

div1"].height[];

20

let height = $["

div1"].height[];

21

let height = getComputedStyle[document.getElementById["div1"]].height;

28

let height = $["

div1"].innerHeight[];

9

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

0

let height = $["

div1"].height[];

8

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].height[];

15

let height = $["

div1"].height[];

4

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = document.getElementById["div1"].clientHeight;

5

let height = $["

div1"].height[];

4

// If you need height of div excluding margin/padding/border $['

div1'].height[];

// If you need height of div with padding but without border + margin $['

div1'].innerHeight[];

// If you need height of div including padding and border $['

div1'].outerHeight[];

// For including border + margin + padding, can use $['

div1'].outerHeight[true];

8

let height = $["

div1"].height[];

3

let height = $["

div1"].height[];

4

Chủ Đề