how to set height dynamically in jquery code example
Example 1: how to set height dynamically in jquery
// Calculate height according to the div width
$(function() {
var myDivWidth = $(".main-div").css("width") + "px";
// the variable will now have our div width
$(".main-div").css("height", myDivWidth)
// Another Way
$(".main-div").css({
"height": myDivWidth
})
})
Example 2: jquery set div height dynamically
$(document).ready(function() {
var divHeight = $('.col-1').height();
$('.col-2').css('min-height', divHeight+'px');
});
Example 3: jquery get div height dynamically
$('elem').height();