height()
methodYou can set the height of a <div>
box dynamically using the jQuery height()
method.
The height()
method simply returns the element's height as unit-less pixel value. However calling the height(value)
method sets the height of the element, where the value can be either a string (e.g. 100%, 50px, 25em, auto etc.) or a number. If only a number is provided for the value, jQuery assumes it as a pixel unit. Let's try out an example and see how it works:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Set a DIV height</title>
<style>
.box{
background: #f2f2f2;
border: 1px solid #ccc;
}
</style>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
$(document).ready(function(){
$(".set-height-btn").click(function(){
var newHeight = $(".input-height").val();
$(".box").height(newHeight);
});
});
</script>
</head>
<body>
<form>
<input type="text" class="input-height">
<button type="button" class="set-height-btn">Set Height</button>
<p>Enter the value in input box either as number (e.g. 100, 200) or combination of number and unit (e.g. 100%, 200px, 50em, auto) and click the "Set Height" button.</p>
</form>
<br>
<div class="box">This is simple DIV box</div>
</body>
</html>
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
Ajax CRUD example in Laravel 5.5 application
Hello, everyone in this post we share wi...Laravel 8 Instamojo Payment Gateway Integration
Today we visually perceive How to integr...How to Use select2.js
Select2.js is the simple jQuery plugin t...How to create custom 404 page in laravel
In this tutorials, i am showing to how t...How to remove white space from the end of a string in PHP
Use the PHP rtrim() function...