jQuery innerHeight()

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

jQuery innerHeight()

The jQuery innerHeight () method is used to return the inner height of first matched element. It includes padding but not border and margin.

In the above image, you can see that innerHeight () method includes padding but not border and margin.

Syntax:

  1. $(selector).innerHeight()  

Example of jQuery innerHeight() method

Let's take an example to demonstrate the effect of jQuery innerHeight() method.

  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>  
  5. <script>  
  6. $(document).ready(function(){  
  7.     $("button").click(function(){  
  8.         alert("Inner height of the div is: " + $("div").innerHeight());  
  9.     });  
  10. });  
  11. </script>  
  12. </head>  
  13. <body>  
  14. <div style="height:100px;width:500px;padding:10px;margin:3px;border:1px solid blue;background-color:lightpink;"></div><br>  
  15. <button>Click here to get the inner height of the div</button>  
  16. </body>  
  17. </html>  

Test it Now

jQuery innerHeight() example 2

Let's take an example to demonstrate how to change the inner height of each div.

  1. <!DOCTYPE html>  
  2. <html lang="en">  
  3. <head>  
  4.   <meta charset="utf-8">  
  5.   <title>innerHeight demo</title>  
  6.   <style>  
  7. div {  
  8.   width: 60px;  
  9.   padding: 10px;  
  10.   height: 100px;  
  11.   float: left;  
  12.   margin: 5px;  
  13.   background: orange;  
  14.   cursor: pointer;  
  15. }  
  16. .mod {  
  17.   background: green;  
  18.   cursor: default;  
  19. }  
  20. </style>  
  21. <script src="https://code.jquery.com/jquery-1.10.2.js"></script>  
  22. </head>  
  23. <body>  
  24. <div>A</div>  
  25. <div>B</div>  
  26. <div>C</div>  
  27. <div>D</div>  
  28. <div>E</div>  
  29. <script>  
  30. var modHeight = 80;  
  31. $( "div" ).one( "click", function() {  
  32.   $( this ).innerHeight( modHeight ).addClass( "mod" );  
  33.   modHeight -8;  
  34. });  
  35. </script>  
  36. </body>  
  37. </html>  

Test it Now