The height() method in JQuery is used to get and set the height of an HTML element.
<html> <head> <title> My First Programme </title> <script src = "https://cdnjs.cloudflare.com/ajax/libs/JQUERY/3.3.1/jquery.min.js"> </script> </head> <body> <h1> JQuery </h1> <p style = "background-color:violet; height:100px"> Hello World </p> <button> Click it </button> <script> $('button').click( function() { alert("The height of the p element is : "+$('p').height()); }); </script> </body> </html>
So, if we look at the above code, we have a <p> element.
<p style = "background-color:violet; height:100px"> Hello World </p>
And we have a <button> element,
<button> Click it </button>
And on button click, the JQuery statement gets triggered,
$('button').click( function() { alert("The height of the p element is : "+$('p').height()); });
And an alert is generated,
alert("The height of the p element is : "+$('p').height());
Now, if we see the output (i.e. The alert),
You get the height of the <p> element (i.e. 100).
This is because the height() method is used to get the height of the <p> element.
<html> <head> <title> My First Programme </title> <script src = "https://cdnjs.cloudflare.com/ajax/libs/JQUERY/3.3.1/jquery.min.js"> </script> </head> <body> <h1> JQuery </h1> <p style = "background-color:violet;"> Hello World </p> <button> Click it </button> <script> $('button').click(function(){ $('p').height("100px"); }); </script> </body> </html>
So, if we look at the above code, we have a <p> element.
<p style = "background-color:violet;"> Hello World </p>
And we have a <button> element,
<button> Click it </button>
And on button click, the JQuery statement gets triggered,
$('button').click( function() { $('p').height("100px"); });
And the height() method is used to set the height of the <p> element to 100px.
$('p').height("100px");
Now, if we see the output, the height of the <p> element got increased to 100px.