jQuery > Manipulations methods

.height() - Get & set height of element in jQuery

How to get and set the height of an element in jQuery?


To get and set the height of an html element, height() method can be used. If we do not pass parameter value to the .height() method, it gets the current height of the element and if we pass parameter to the .height() method, it sets the parameter value as height of the element.

 <script>
      $("h1").css("background", "#c0c0c0").height("200px");
  </script>

Above code snippet will first change the background color of the <h1> tag and then set the height of the “h1” tag to 200px.

 <script>
      alert($("h1").height());
  </script>

Above code snippet will show the height of the “h1” element in JavaScript alert.

 Views: 4879 | Post Order: 51



Write for us






Hosting Recommendations