jQuery innerHeight() function is used to get the current computed inner height (including padding but not the border) for the first element in the set of matched elements or sets the inner height of every matched element.
Try it Yourself - Copy paste code in Online HTML Editor to see the result
Try it Yourself - Copy paste code in Online HTML Editor to see the result
Example - Get the innerHeight of a paragraph
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>innerHeight demo</title>
<style>
p {
margin: 10px;
padding: 5px;
border: 2px solid #666;
}
</style>
<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
</head>
<body>
<p>Hello</p>
<p></p>
<script>
var p = $("p").first();
$("p").last().text("innerHeight:" + p.innerHeight());
</script>
</body>
</html>
Example 2 - Change the inner height of each div the first time it is clicked (and change its color)
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>innerHeight demo</title>
<style>
div {
width: 60px;
padding: 10px;
height: 70px;
float: left;
margin: 5px;
background: red;
cursor: pointer;
}
.mod {
background: blue;
cursor: default;
}
</style>
<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
</head>
<body>
<div>sourcecodeexamples</div>
<div>sourcecodeexamples</div>
<div>sourcecodeexamples</div>
<div>sourcecodeexamples</div>
<div>sourcecodeexamples</div>
<script>
var modHeight = 60;
$("div").one("click", function() {
$(this).innerHeight(modHeight).addClass("mod");
modHeight -= 8;
});
</script>
</body>
</html>
Comments
Post a Comment