jQuery height Method


jQuery height Method : is used to get or set the height of selected element. If want to add hight of an element dynamically use .height(height) method eg. .height(100) where 100 is height in pixel.


jQuery height Method Syntax 1 Get height

Here is syntax of height method-

$(selector).height();

jQuery height() Method Example 1

Here is an example of height() method

<script type="text/javascript">
         $(document).ready(function(){ 
              $( "#heightExample" ).on( "click", function(event) {             
                  var x = $("#myDiv").height();       
                   alert(x+"px");            
              });
               
          });
</script>

Try it »

Syntax 2 – Set Height

$(selector).height(width);

height(px): Height in pixel.

jQuery height() Method Example 2

<script type="text/javascript">
         $(document).ready(function(){ 
              $( "#widthExample" ).on( "click", function(event) {             
                $("#myDiv").height(600);               
              });
               
          });
</script>

Try it »


Advertisements

Add Comment

📖 Read More