jqueryexample.com jQuery examples - get/set height() - jqueryexample.com

jQuery examples – get/set height() by jqueryexample

jQuery makes easy to work with the dimensions of elements and even the browser window. You can use height() methods for measurement the dimensions or set the height of selected element.In this tutorial i will show you how to get height of an element.
1. $(selector).height(); //It will return the height of first element.


Set Height:

Put jQuery on your server and use the following code to reference the script.

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$("#getp").click(function () {
alert("height of paragraph: " + $("p").height());
$("#getd").click(function () {
alert("height of document: " + $(document).height());
$("#getw").click(function () {
alert("height of window: " + $(window).height());
<button id="getp">Get Paragraph Height</button>
<button id="getd">Get Document Height</button>
<button id="getw">Get Window Height</button>
<div> </div>
<p> Sample paragraph to test height

Note: The width() and height() is simply the computed size of the element. If you use innerWidth() and innerHeight(), padding is included in the returned values. If you use the outerWidth() and outerHeight() methods, both padding and border is included in the returned values.

Did you like this? Share it:


No comments yet, be the first.

Leave a Comment