Home Tutorial Jquery jQuery "height" method

 
 

Share on Google+Share on Google+
jQuery "height" method
Posted on: August 6, 2010 at 12:00 AM
Advertisement
In this tutorial ,we will discuss about "height" method of jQuery.

jQuery "height" method

In this tutorial ,we will discuss about "height" method of jQuery. The difference between .css('height') and .height() is that the latter returns a unit-less pixel value (for example, 400) while the former returns a value with units intact (for example, 400px). The .height() method is recommended when an element's height needs to be used in a mathematical calculation.

height.html

<!DOCTYPE html>
<html>
<head>
<style>
body { background:#4682B4; }
button { font-size:12px; margin:2px; }
p { width:150px; border:1px red solid; }
div { color:red; font-weight:bold; }
</style>
<script src="jquery-1.4.2.js"></script>
</head>
<body>
<button id="getp">Get Paragraph Height</button>
<button id="getd">Get Document Height</button>
<button id="getw">Get Window Height</button>

<div>&nbsp;</div>
<p>
Sample paragraph to test height
</p>
<script>
function showHeight(ele, h) {
$("div").text("The height for the " + ele +
" is " + h + "px.");
}
$("#getp").click(function () {
showHeight("paragraph", $("p").height());
});
$("#getd").click(function () {
showHeight("document", $(document).height());
});
$("#getw").click(function () {
showHeight("window", $(window).height());
});

</script>
</body>
</html>

OUTPUT

Download Source Code

Click here to see demo

Advertisement

Related Tags for jQuery "height" method:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: August 6, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com